MessageHandler.c 629 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267
  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_send = 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 struct Charger_Info Charger;
  108. extern sqlite3 *db;
  109. int TransactionMessageAttemptsGet(void);
  110. int TransactionMessageRetryIntervalGet(void);
  111. int GetOcppConnStatus(void);
  112. void SetOcppConnStatus(uint8_t status);
  113. int setKeyValue(char *key, char *value);
  114. void OCPP_get_TableAuthlocalAllData(void);
  115. void processUnkownKey(void);
  116. struct StructOCPPMeterValue
  117. {
  118. unsigned char TimeStamp[28];
  119. struct StructSampledValue SampledValue[10];
  120. };
  121. struct ClientTime
  122. {
  123. unsigned int Heartbeat;
  124. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  125. unsigned int StartTransaction;
  126. unsigned int StopTransaction;
  127. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }clientTime;
  129. typedef union
  130. {
  131. //Operations Initiated by Central System
  132. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  133. struct
  134. {
  135. //CsMsgValue[0]
  136. unsigned char StatusNotificationReq :1; //bit 0,
  137. unsigned char StatusNotificationConf :1; //bit 0,
  138. unsigned char :6; //bit 2~7
  139. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  140. }CpinitiateMsg;
  141. CpinitiateMsg cpinitateMsg;
  142. //==========================================
  143. // Init all Enumeration & Mapping String
  144. //==========================================
  145. /*ChargePointErrorCode*/
  146. typedef enum {
  147. ConnectorLockFailure,
  148. EVCommunicationError,
  149. GroundFailure,
  150. HighTemperature,
  151. InternalError,
  152. LocalListConflict,
  153. NoError,
  154. OtherError,
  155. OverCurrentFailure,
  156. OverVoltage,
  157. PowerMeterFailure,
  158. PowerSwitchFailure,
  159. ReaderFailure,
  160. ResetFailure,
  161. UnderVoltage,
  162. WeakSignal
  163. } ChargePointErrorCode;
  164. #if 0
  165. static char *ChargePointErrorCodeStr[] = {
  166. MACROSTR(ConnectorLockFailure),
  167. MACROSTR(EVCommunicationError),
  168. MACROSTR(GroundFailure),
  169. MACROSTR(HighTemperature),
  170. MACROSTR(InternalError),
  171. MACROSTR(LocalListConflict),
  172. MACROSTR(NoError),
  173. MACROSTR(OtherError),
  174. MACROSTR(OverCurrentFailure),
  175. MACROSTR(OverVoltage),
  176. MACROSTR(PowerMeterFailure),
  177. MACROSTR(PowerSwitchFailure),
  178. MACROSTR(ReaderFailure),
  179. MACROSTR(ResetFailure),
  180. MACROSTR(UnderVoltage),
  181. MACROSTR(WeakSignal)
  182. };
  183. #endif
  184. /*ChargePointStatus*/
  185. typedef enum {
  186. Available =0,
  187. Preparing,
  188. Charging,
  189. SuspendedEVSE,
  190. SuspendedEV,
  191. Finishing,
  192. Reserved,
  193. Unavailable,
  194. Faulted
  195. } ChargePointStatus;
  196. static char * ChargePointStatusStr[] = {
  197. MACROSTR(Available),
  198. MACROSTR(Preparing),
  199. MACROSTR(Charging),
  200. MACROSTR(SuspendedEVSE),
  201. MACROSTR(SuspendedEV),
  202. MACROSTR(Finishing),
  203. MACROSTR(Reserved),
  204. MACROSTR(Unavailable),
  205. MACROSTR(Faulted)
  206. };
  207. /*AvailabilityType*/
  208. typedef enum {
  209. RegistrationStatus_Accepted,
  210. RegistrationStatus_Pending,
  211. RegistrationStatus_Rejected
  212. } RegistrationStatus;
  213. static char *RegistrationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Pending),
  216. MACROSTR(Rejected)
  217. };
  218. /*AvailabilityType*/
  219. typedef enum {
  220. Inoperative,
  221. Operative
  222. } AvailabilityType;
  223. static char *AvailabilityTypeStr[] = {
  224. MACROSTR(Inoperative),
  225. MACROSTR(Operative)
  226. };
  227. /*AvailabilityStatus*/
  228. typedef enum {
  229. Accepted,
  230. Rejected,
  231. Scheduled
  232. } AvailabilityStatus;
  233. static char *AvailabilityStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected),
  236. MACROSTR(Scheduled)
  237. };
  238. /*ConfigurationStatus*/
  239. typedef enum {
  240. ConfigurationStatus_Accepted,
  241. ConfigurationStatus_Rejected,
  242. RebootRequired,
  243. NotSupported
  244. } ConfigurationStatus;
  245. static char *ConfigurationStatusStr[] = {
  246. MACROSTR(Accepted),
  247. MACROSTR(Rejected),
  248. MACROSTR(RebootRequired),
  249. MACROSTR(NotSupported)
  250. };
  251. /*ClearCacheStatus*/
  252. typedef enum {
  253. ClearCacheStatus_Accepted,
  254. ClearCacheStatus_Rejected
  255. } ClearCacheStatus;
  256. static char *ClearCacheStatusStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected)
  259. };
  260. /*ChargingProfilePurposeType*/
  261. typedef enum {
  262. ChargePointMaxProfile,
  263. TxDefaultProfile,
  264. TxProfile
  265. } ChargingProfilePurposeType;
  266. static char *ChargingProfilePurposeTypeStr[] = {
  267. MACROSTR(ChargePointMaxProfile),
  268. MACROSTR(TxDefaultProfile),
  269. MACROSTR(TxProfile)
  270. };
  271. /*ChargingProfileStatus*/
  272. typedef enum {
  273. ChargingProfileStatus_Accepted,
  274. ChargingProfileStatus_Rejected,
  275. ChargingProfileStatus_NotSupported
  276. } ChargingProfileStatus;
  277. static char *ChargingProfileStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected),
  280. MACROSTR(NotSupported)
  281. };
  282. /*ClearChargingProfileStatus*/
  283. typedef enum {
  284. ClearChargingProfileStatus_Accepted,
  285. ClearChargingProfileStatus_Unknown
  286. } ClearChargingProfileStatus;
  287. static char *ClearChargingProfileStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Unknown)
  290. };
  291. /*GetCompositeScheduleStatus*/
  292. typedef enum {
  293. GetCompositeScheduleStatus_Accepted,
  294. GetCompositeScheduleStatus_Rejected
  295. } GetCompositeScheduleStatus;
  296. static char *GetCompositeScheduleStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected)
  299. };
  300. /*ChargingRateUnitType*/
  301. typedef enum {
  302. ChargingRateUnitType_W,
  303. ChargingRateUnitType_A
  304. } ChargingRateUnitType;
  305. /*AuthorizationStatus*/
  306. typedef enum {
  307. AuthorizationStatus_Accepted ,
  308. AuthorizationStatus_Blocked ,
  309. AuthorizationStatus_Expired ,
  310. AuthorizationStatus_Invalid ,
  311. AuthorizationStatus_ConcurrentTx
  312. } AuthorizationStatus;
  313. /*UpdateType*/
  314. typedef enum {
  315. Differential ,
  316. Full
  317. } UpdateType;
  318. static char *UpdateTypeStr[] = {
  319. MACROSTR(Differential),
  320. MACROSTR(Full)
  321. };
  322. /*UpdateStatus*/
  323. typedef enum {
  324. UpdateStatus_Accepted ,
  325. UpdateStatus_Failed ,
  326. UpdateStatus_NotSupported ,
  327. UpdateStatus_VersionMismatch
  328. } UpdateStatus;
  329. static char *UpdateStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Failed),
  332. MACROSTR(NotSupported),
  333. MACROSTR(VersionMismatch)
  334. };
  335. /*RemoteStartStopStatus*/
  336. typedef enum {
  337. RemoteStartStopStatus_Accepted,
  338. RemoteStartStopStatus_Rejected
  339. } RemoteStartStopStatus;
  340. static char *RemoteStartStopStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Rejected)
  343. };
  344. /*ReservationStatus*/
  345. typedef enum {
  346. ReservationStatus_Accepted,
  347. ReservationStatus_Faulted,
  348. ReservationStatus_Occupied,
  349. ReservationStatus_Rejected,
  350. ReservationStatus_Unavailable
  351. } ReservationStatus;
  352. static char *ReservationStatusStr[] = {
  353. MACROSTR(Accepted),
  354. MACROSTR(Faulted),
  355. MACROSTR(Occupied),
  356. MACROSTR(Rejected),
  357. MACROSTR(Unavailable)
  358. };
  359. /*ResetType*/
  360. typedef enum {
  361. Hard,
  362. Soft
  363. } ResetType;
  364. static char *ResetTypeStr[] = {
  365. MACROSTR(Hard),
  366. MACROSTR(Soft)
  367. };
  368. /*ResetStatus*/
  369. typedef enum {
  370. ResetStatus_Accepted,
  371. ResetStatus_Rejected
  372. } ResetStatus;
  373. static char *ResetStatusStr[] = {
  374. MACROSTR(Accepted),
  375. MACROSTR(Rejected)
  376. };
  377. /*DiagnosticsStatus*/
  378. typedef enum {
  379. DiagnosticsStatus_Idle,
  380. DiagnosticsStatus_Uploaded,
  381. DiagnosticsStatus_UploadFailed,
  382. DiagnosticsStatus_Uploading
  383. } DiagnosticsStatus;
  384. static char * DiagnosticsStatusStr[] = {
  385. MACROSTR(Idle),
  386. MACROSTR(Uploaded),
  387. MACROSTR(UploadFailed),
  388. MACROSTR(Uploading)
  389. };
  390. /*FirmwareStatus*/
  391. typedef enum {
  392. FirmwareStatus_Downloaded,
  393. FirmwareStatus_DownloadFailed,
  394. FirmwareStatus_Downloading,
  395. FirmwareStatus_Idle,
  396. FirmwareStatus_InstallationFailed,
  397. FirmwareStatus_Installing,
  398. FirmwareStatus_Installed
  399. } FirmwareStatus;
  400. static char * FirmwareStatusStr[] = {
  401. MACROSTR(Downloaded),
  402. MACROSTR(DownloadFailed),
  403. MACROSTR(Downloading),
  404. MACROSTR(Idle),
  405. MACROSTR(InstallationFailed),
  406. MACROSTR(Installing),
  407. MACROSTR(Installed)
  408. };
  409. /*MessageTrigger*/
  410. typedef enum {
  411. BootNotification,
  412. DiagnosticsStatusNotification,
  413. FirmwareStatusNotification,
  414. Heartbeat,
  415. MeterValues,
  416. StatusNotification
  417. } MessageTrigger;
  418. static char * MessageTriggerStr[] = {
  419. MACROSTR(BootNotification),
  420. MACROSTR(DiagnosticsStatusNotification),
  421. MACROSTR(FirmwareStatusNotification),
  422. MACROSTR(Heartbeat),
  423. MACROSTR(MeterValues),
  424. MACROSTR(StatusNotification)
  425. };
  426. /*TriggerMessageStatus*/
  427. typedef enum {
  428. TriggerMessageStatus_Accepted ,
  429. TriggerMessageStatus_Rejected ,
  430. TriggerMessageStatus_NotImplemented
  431. } TriggerMessageStatus;
  432. static char * TriggerMessageStatusStr[] = {
  433. MACROSTR(Accepted),
  434. MACROSTR(Rejected),
  435. MACROSTR(NotImplemented)
  436. };
  437. /*UnlockStatus*/
  438. typedef enum {
  439. Unlocked,
  440. UnlockFailed,
  441. UnlockStatus_NotSupported
  442. } UnlockStatus;
  443. static char * UnlockStatusStr[] = {
  444. MACROSTR(Unlocked),
  445. MACROSTR(UnlockFailed),
  446. MACROSTR(NotSupported)
  447. };
  448. /*StopTransactionReason*/
  449. typedef enum {
  450. EmergencyStop,
  451. EVDisconnected,
  452. HardReset,
  453. Local,
  454. Other,
  455. PowerLoss,
  456. Reboot,
  457. Remote,
  458. SoftReset,
  459. UnlockCommand,
  460. DeAuthorized
  461. } StopTransactionReason;
  462. #if 0
  463. static char * StopTransactionReasonStr[] = {
  464. MACROSTR(EmergencyStop),
  465. MACROSTR(EVDisconnected),
  466. MACROSTR(HardReset),
  467. MACROSTR(Local),
  468. MACROSTR(Other),
  469. MACROSTR(PowerLoss),
  470. MACROSTR(Reboot),
  471. MACROSTR(Remote),
  472. MACROSTR(SoftReset),
  473. MACROSTR(UnlockCommand),
  474. MACROSTR(DeAuthorized)
  475. };
  476. #endif
  477. /*CancelReservationStatus*/
  478. typedef enum {
  479. CancelReservationStatus_Accepted,
  480. CancelReservationStatus_Rejected
  481. } CancelReservationStatus;
  482. static char * CancelReservationStatusStr[] = {
  483. MACROSTR(Accepted),
  484. MACROSTR(Rejected)
  485. };
  486. /*ReadingContext*/
  487. typedef enum {
  488. ReadingContext_Interruption_Begin,
  489. ReadingContext_Interruption_End,
  490. ReadingContext_Other,
  491. ReadingContext_Sample_Clock,
  492. ReadingContext_Sample_Periodic ,
  493. ReadingContext_Transaction_Begin ,
  494. ReadingContext_Transaction_End,
  495. ReadingContext_Trigger
  496. } ReadingContext;
  497. static char * ReadingContextStr[] = {
  498. MACROSTR(Interruption.Begin),
  499. MACROSTR(Interruption.End),
  500. MACROSTR(Other),
  501. MACROSTR(Sample.Clock),
  502. MACROSTR(Sample.Periodic),
  503. MACROSTR(Transaction.Begin),
  504. MACROSTR(Transaction.End),
  505. MACROSTR(Trigger)
  506. };
  507. /*ValueFormat*/
  508. typedef enum {
  509. Raw,
  510. SignedData
  511. } ValueFormat;
  512. static char * ValueFormatStr[] = {
  513. MACROSTR(Raw),
  514. MACROSTR(SignedData)
  515. };
  516. /*Measurand*/
  517. typedef enum {
  518. Current_Export ,
  519. Current_Import,
  520. Current_Offered,
  521. Energy_Active_Export_Register,
  522. Energy_Active_Import_Register,
  523. Energy_Reactive_Export_Register,
  524. Energy_Reactive_Import_Register,
  525. Energy_Active_Export_Interval,
  526. Energy_Active_Import_Interval,
  527. Energy_Reactive_Export_Interval,
  528. Energy_Reactive_Import_Interval,
  529. Frequency,
  530. Power_Active_Export ,
  531. Power_Active_Import,
  532. Power_Factor,
  533. Power_Offered,
  534. Power_Reactive_Export,
  535. Power_Reactive_Import,
  536. RPM,
  537. SoC,
  538. Temperature ,
  539. Voltage
  540. } Measurand;
  541. static char * MeasurandStr[] = {
  542. MACROSTR(Current.Export),
  543. MACROSTR(Current.Import),
  544. MACROSTR(Current.Offered),
  545. MACROSTR(Energy.Active.Export.Register),
  546. MACROSTR(Energy.Active.Import.Register),
  547. MACROSTR(Energy.Reactive.Export.Register),
  548. MACROSTR(Energy.Reactive.Import.Register),
  549. MACROSTR(Energy.Active.Export.Interval),
  550. MACROSTR(Energy.Active.Import.Interval),
  551. MACROSTR(Energy.Reactive.Export.Interval),
  552. MACROSTR(Energy.Reactive.Import.Interval),
  553. MACROSTR(Frequency),
  554. MACROSTR(Power.Active.Export),
  555. MACROSTR(Power.Active.Import),
  556. MACROSTR(Power.Factor),
  557. MACROSTR(Power.Offered),
  558. MACROSTR(Power.Reactive.ExportMACROSTR),
  559. MACROSTR(Power.Reactive.Import),
  560. MACROSTR(RPM),
  561. MACROSTR(SoC),
  562. MACROSTR(Temperature),
  563. MACROSTR(Voltage)
  564. };
  565. /*Location*/
  566. typedef enum {
  567. Location_Body,
  568. Location_Cable,
  569. Location_EV,
  570. Location_Inlet ,
  571. Location_Outlet
  572. } Location;
  573. static char * LocationStr[] = {
  574. MACROSTR(Body),
  575. MACROSTR(Cable),
  576. MACROSTR(EV),
  577. MACROSTR(Inlet),
  578. MACROSTR(Outlet)
  579. };
  580. /*Phase*/
  581. typedef enum {
  582. L1,
  583. L2,
  584. L3,
  585. N,
  586. L1_N,
  587. L2_N,
  588. L3_N,
  589. L1_L2,
  590. L2_L3,
  591. L3_L1
  592. } Phase;
  593. static char * PhaseStr[] = {
  594. MACROSTR(L1),
  595. MACROSTR(L2),
  596. MACROSTR(L3),
  597. MACROSTR(N),
  598. MACROSTR(L1-N),
  599. MACROSTR(L2-N),
  600. MACROSTR(L3-N),
  601. MACROSTR(L1-L2),
  602. MACROSTR(L2-L3),
  603. MACROSTR(L3-L1)
  604. };
  605. /*UnitOfMeasure*/
  606. typedef enum {
  607. UnitOfMeasure_Wh,
  608. UnitOfMeasure_kWh ,
  609. UnitOfMeasure_varh ,
  610. UnitOfMeasure_kvarh ,
  611. UnitOfMeasure_W ,
  612. UnitOfMeasure_kW ,
  613. UnitOfMeasure_VA ,
  614. UnitOfMeasure_kVA ,
  615. UnitOfMeasure_var ,
  616. UnitOfMeasure_kvar ,
  617. UnitOfMeasure_A ,
  618. UnitOfMeasure_V ,
  619. UnitOfMeasure_Celsius ,
  620. UnitOfMeasure_Fahrenheit ,
  621. UnitOfMeasure_K ,
  622. UnitOfMeasure_Percent
  623. } UnitOfMeasure;
  624. static char * UnitOfMeasureStr[] = {
  625. MACROSTR(Wh),
  626. MACROSTR(kWh),
  627. MACROSTR(varh),
  628. MACROSTR(kvarh),
  629. MACROSTR(W),
  630. MACROSTR(kW),
  631. MACROSTR(VA),
  632. MACROSTR(kVA),
  633. MACROSTR(var),
  634. MACROSTR(kvar),
  635. MACROSTR(A),
  636. MACROSTR(V),
  637. MACROSTR(Celsius),
  638. MACROSTR(Fahrenheit),
  639. MACROSTR(K),
  640. MACROSTR(Percent)
  641. };
  642. enum LocalAuthListManagementProfile{
  643. LocalAuthListEnabled=0,
  644. LocalAuthListMaxLength,
  645. SendLocalListMaxLength,
  646. _LocalAuthListManagementProfile_CNT
  647. };
  648. enum ReservationProfile{
  649. ReserveConnectorZeroSupported
  650. };
  651. enum SmartChargingProfile{
  652. ChargeProfileMaxStackLevel,
  653. ChargingScheduleAllowedChargingRateUnit,
  654. ChargingScheduleMaxPeriods,
  655. ConnectorSwitch3to1PhaseSupported,
  656. MaxChargingProfilesInstalled
  657. };
  658. enum ChargerSystemStatus{
  659. ChargerSystemStatus_Booting,
  660. ChargerSystemStatus_Idle,
  661. ChargerSystemStatus_Authorizing,
  662. ChargerSystemStatus_Preparing,
  663. ChargerSystemStatus_Charging,
  664. ChargerSystemStatus_Terminating,
  665. ChargerSystemStatus_Alarm,
  666. ChargerSystemStatus_Fault
  667. };
  668. enum GetConfigurationKey {
  669. GetConfiguration_AllowOfflineTxForUnknownId=0,
  670. GetConfiguration_AuthorizationCacheEnabled,
  671. GetConfiguration_AuthorizeRemoteTxRequests,
  672. GetConfiguration_BlinkRepeat,
  673. GetConfiguration_ClockAlignedDataInterval,
  674. GetConfiguration_ConnectionTimeOut,
  675. GetConfiguration_GetConfigurationMaxKeys,
  676. GetConfiguration_HeartbeatInterval,
  677. GetConfiguration_LightIntensity,
  678. GetConfiguration_LocalAuthorizeOffline,
  679. GetConfiguration_LocalPreAuthorize,
  680. GetConfiguration_MaxEnergyOnInvalidId,
  681. GetConfiguration_MeterValuesAlignedData,
  682. GetConfiguration_MeterValuesAlignedDataMaxLength,
  683. GetConfiguration_MeterValuesSampledData,
  684. GetConfiguration_MeterValuesSampledDataMaxLength,
  685. GetConfiguration_MeterValueSampleInterval,
  686. GetConfiguration_MinimumStatusDuration,
  687. GetConfiguration_NumberOfConnectors,
  688. GetConfiguration_ResetRetries,
  689. GetConfiguration_ConnectorPhaseRotation,
  690. GetConfiguration_ConnectorPhaseRotationMaxLength,
  691. GetConfiguration_StopTransactionOnEVSideDisconnect,
  692. GetConfiguration_StopTransactionOnInvalidId,
  693. GetConfiguration_StopTxnAlignedData,
  694. GetConfiguration_StopTxnAlignedDataMaxLength,
  695. GetConfiguration_StopTxnSampledData,
  696. GetConfiguration_StopTxnSampledDataMaxLength,
  697. GetConfiguration_SupportedFeatureProfiles,
  698. GetConfiguration_SupportedFeatureProfilesMaxLength,
  699. GetConfiguration_TransactionMessageAttempts,
  700. GetConfiguration_TransactionMessageRetryInterval,
  701. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  702. GetConfiguration_WebSocketPingInterval,
  703. GetConfiguration_LocalAuthListEnabled,
  704. GetConfiguration_LocalAuthListMaxLength,
  705. GetConfiguration_SendLocalListMaxLength,
  706. GetConfiguration_ReserveConnectorZeroSupported,
  707. GetConfiguration_ChargeProfileMaxStackLevel,
  708. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  709. GetConfiguration_ChargingScheduleMaxPeriods,
  710. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  711. GetConfiguration_MaxChargingProfilesInstalled,
  712. };
  713. //GetConfiguration Array
  714. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  715. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  717. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  718. //==========================================
  719. // Check time passed since today
  720. //==========================================
  721. long long DiffTimebWithNow(struct timeb ST)
  722. {
  723. //return milli-second
  724. struct timeb ET;
  725. long long StartTime,StopTime;
  726. ftime(&ET);
  727. StartTime=(long long)ST.time;
  728. StopTime=(long long)ET.time;
  729. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  730. }
  731. int getTimePassSinceToday()
  732. {
  733. int result = -1;
  734. time_t t;
  735. struct tm *tmStartToday;
  736. struct timeb tbStartToday;
  737. t=time(NULL);
  738. tmStartToday=localtime(&t);
  739. tmStartToday->tm_hour = 0;
  740. tmStartToday->tm_min = 0;
  741. tmStartToday->tm_sec = 0;
  742. tbStartToday.time = mktime(tmStartToday);
  743. tbStartToday.millitm = 0;
  744. result = DiffTimebWithNow(tbStartToday)/1000;
  745. return result;
  746. }
  747. //==========================================
  748. // GetCompositeSchedule logic related function
  749. //==========================================
  750. int DiffTimebSec(struct timeb ST, struct timeb ET)
  751. {
  752. //return milli-second
  753. unsigned int StartTime,StopTime;
  754. StartTime=(unsigned int)ST.time;
  755. StopTime=(unsigned int)ET.time;
  756. return (StopTime-StartTime);
  757. }
  758. int DiffTimebWithNowSec(struct timeb ST)
  759. {
  760. //return milli-second
  761. struct timeb ET;
  762. unsigned int StartTime,StopTime;
  763. ftime(&ET);
  764. StartTime=(unsigned int)ST.time;
  765. StopTime=(unsigned int)ET.time;
  766. return (StopTime-StartTime);
  767. }
  768. int getStartStop(uint8_t *start, uint8_t *stop)
  769. {
  770. int result = -1;
  771. struct tm tmStart;
  772. struct timeb tbStart;
  773. struct tm tmStop;
  774. struct timeb tbStop;
  775. 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) &&
  776. (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))
  777. {
  778. tmStart.tm_year -= 1900;
  779. tmStart.tm_mon -= 1;
  780. tbStart.time = mktime(&tmStart);
  781. tbStart.millitm = 0;
  782. tmStop.tm_year -= 1900;
  783. tmStop.tm_mon -= 1;
  784. tbStop.time = mktime(&tmStop);
  785. tbStop.millitm = 0;
  786. result = DiffTimebSec(tbStart, tbStop);
  787. }
  788. else
  789. {
  790. DEBUG_WARN("Start or stop date parsing error.\r\n");
  791. }
  792. return result;
  793. }
  794. int getStartSinceToday(uint8_t *stop)
  795. {
  796. int result = -1;
  797. time_t t;
  798. struct tm *tmStartToday;
  799. struct timeb tbStartToday;
  800. struct tm tmStop;
  801. struct timeb tbStop;
  802. 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))
  803. {
  804. t=time(NULL);
  805. tmStartToday=localtime(&t);
  806. tmStartToday->tm_hour = 0;
  807. tmStartToday->tm_min = 0;
  808. tmStartToday->tm_sec = 0;
  809. tbStartToday.time = mktime(tmStartToday);
  810. tmStop.tm_year -= 1900;
  811. tmStop.tm_mon -= 1;
  812. tbStop.time = mktime(&tmStop);
  813. tbStop.millitm = 0;
  814. result = DiffTimebSec(tbStartToday, tbStop);
  815. }
  816. return result;
  817. }
  818. int getStartSinceWeek(uint8_t *stop)
  819. {
  820. int result = -1;
  821. time_t t;
  822. struct tm *tmStartWeek;
  823. struct timeb tbStartWeek;
  824. struct tm tmStop;
  825. struct timeb tbStop;
  826. 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))
  827. {
  828. t=time(NULL);
  829. tmStartWeek=localtime(&t);
  830. t-=86400*tmStartWeek->tm_wday;
  831. tmStartWeek=localtime(&t);
  832. tmStartWeek->tm_hour = 0;
  833. tmStartWeek->tm_min = 0;
  834. tmStartWeek->tm_sec = 0;
  835. tbStartWeek.time = mktime(tmStartWeek);
  836. tmStop.tm_year -= 1900;
  837. tmStop.tm_mon -= 1;
  838. tbStop.time = mktime(&tmStop);
  839. tbStop.millitm = 0;
  840. result = DiffTimebSec(tbStartWeek, tbStop);
  841. }
  842. return result;
  843. }
  844. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  845. {
  846. FILE *fp;
  847. char profileFileName[128];
  848. char *line = NULL;
  849. size_t len = 0;
  850. time_t CurrentTime;
  851. struct tm *tmComposite;
  852. struct StructChargingProfile maxProfile;
  853. struct StructChargingProfile defaultTxProfile;
  854. struct StructChargingProfile txProfile;
  855. struct StructChargingSchedulePeriod tmpPeriod;
  856. uint8_t limitMax=0;
  857. uint8_t limitDef=0;
  858. uint8_t limitTx=0;
  859. int compositePeriodIdx = 0;
  860. CurrentTime = time(NULL);
  861. tmComposite=localtime(&CurrentTime);
  862. 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);
  863. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  864. compositeProfile->ChargingSchedule.Duration = durationReq;
  865. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  866. {
  867. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  868. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  869. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  870. }
  871. compositeProfile->ChargingProfileId = 0;
  872. compositeProfile->StackLevel = 99 ;
  873. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  874. maxProfile.ChargingProfileId = -1;
  875. defaultTxProfile.ChargingProfileId = -1;
  876. txProfile.ChargingProfileId = -1;
  877. system("yes|rm /tmp/*.json");
  878. system("cp /Storage/OCPP/*.json /tmp");
  879. /*
  880. * Search valid charging profile
  881. */
  882. //DEBUG_INFO("====================================\n");
  883. // Search max profile
  884. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  885. if((access(profileFileName, F_OK))!=-1)
  886. {
  887. fp = fopen(profileFileName, "r");
  888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  889. {
  890. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  893. }
  894. maxProfile.ChargingProfileId = -1;
  895. maxProfile.StackLevel = -1;
  896. while(getline(&line, &len, fp) != -1)
  897. {
  898. json_object *obj = NULL;
  899. obj = json_tokener_parse(line);
  900. if(is_error(obj))
  901. {
  902. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  903. }
  904. else
  905. {
  906. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  907. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  908. )
  909. {
  910. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  911. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  912. )
  913. {
  914. struct tm tmFrom, tmTo;
  915. struct timeb tbFrom, tbTo;
  916. 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) &&
  917. (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))
  918. {
  919. tmFrom.tm_year -= 1900;
  920. tmFrom.tm_mon -= 1;
  921. tbFrom.time = mktime(&tmFrom);
  922. tmTo.tm_year -= 1900;
  923. tmTo.tm_mon -= 1;
  924. tbTo.time = mktime(&tmTo);
  925. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  926. {
  927. if(maxProfile.ChargingProfileId == -1)
  928. DEBUG_INFO("MaxProfile found.\n");
  929. else
  930. DEBUG_INFO("MaxProfile updated.\n");
  931. // Required item
  932. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  933. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  934. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  935. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  936. 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++)
  937. {
  938. 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"));
  939. 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")));
  940. 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?
  941. 3:
  942. 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")));
  943. }
  944. // Optional item
  945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  946. {
  947. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  948. }
  949. else
  950. {
  951. sprintf((char*)maxProfile.ValidFrom, " ");
  952. }
  953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  954. {
  955. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  956. }
  957. else
  958. {
  959. sprintf((char*)maxProfile.ValidTo, " ");
  960. }
  961. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  962. {
  963. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  964. }
  965. else
  966. {
  967. sprintf((char*)maxProfile.RecurrencyKind, " ");
  968. }
  969. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  970. {
  971. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  972. }
  973. else
  974. {
  975. maxProfile.TransactionId = -1;
  976. }
  977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  978. {
  979. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  980. }
  981. else
  982. {
  983. maxProfile.ChargingSchedule.Duration = -1;
  984. }
  985. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  986. {
  987. 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")));
  988. }
  989. else
  990. {
  991. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  992. }
  993. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  994. {
  995. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  996. }
  997. else
  998. {
  999. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1000. }
  1001. }
  1002. }
  1003. }
  1004. else
  1005. {
  1006. if(maxProfile.ChargingProfileId == -1)
  1007. DEBUG_INFO("MaxProfile found.\n");
  1008. else
  1009. DEBUG_INFO("MaxProfile updated.\n");
  1010. // Required item
  1011. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1012. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1013. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1014. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1015. 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++)
  1016. {
  1017. 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"));
  1018. 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")));
  1019. 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?
  1020. 3:
  1021. 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")));
  1022. }
  1023. // Optional item
  1024. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1025. {
  1026. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1027. }
  1028. else
  1029. {
  1030. sprintf((char*)maxProfile.ValidFrom, " ");
  1031. }
  1032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1033. {
  1034. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1035. }
  1036. else
  1037. {
  1038. sprintf((char*)maxProfile.ValidTo, " ");
  1039. }
  1040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1041. {
  1042. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1043. }
  1044. else
  1045. {
  1046. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1047. }
  1048. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1049. {
  1050. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1051. }
  1052. else
  1053. {
  1054. maxProfile.TransactionId = -1;
  1055. }
  1056. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1057. {
  1058. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1059. }
  1060. else
  1061. {
  1062. maxProfile.ChargingSchedule.Duration = -1;
  1063. }
  1064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1065. {
  1066. 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")));
  1067. }
  1068. else
  1069. {
  1070. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1071. }
  1072. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1073. {
  1074. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1075. }
  1076. else
  1077. {
  1078. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1079. }
  1080. }
  1081. }
  1082. }
  1083. json_object_put(obj);
  1084. }
  1085. fclose(fp);
  1086. /*
  1087. if(maxProfile.ChargingProfileId !=-1)
  1088. {
  1089. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1090. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1091. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1092. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1093. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1094. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1095. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1096. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1097. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1098. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1099. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1100. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1101. {
  1102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1103. {
  1104. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1105. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1106. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1107. }
  1108. }
  1109. }
  1110. else
  1111. DEBUG_INFO("MaxProfile not found.\n");
  1112. DEBUG_INFO("------------------------------------\n");*/
  1113. }
  1114. // Search default tx profile
  1115. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1116. if((access(profileFileName, F_OK))==-1)
  1117. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1118. if((access(profileFileName, F_OK))!=-1)
  1119. {
  1120. fp = fopen(profileFileName, "r");
  1121. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1122. {
  1123. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1124. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1125. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1126. }
  1127. defaultTxProfile.ChargingProfileId = -1;
  1128. defaultTxProfile.StackLevel = -1;
  1129. while(getline(&line, &len, fp) != -1)
  1130. {
  1131. json_object *obj = NULL;
  1132. obj = json_tokener_parse(line);
  1133. if(is_error(obj))
  1134. {
  1135. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1136. }
  1137. else
  1138. {
  1139. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1140. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1141. )
  1142. {
  1143. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1144. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1145. )
  1146. {
  1147. struct tm tmFrom, tmTo;
  1148. struct timeb tbFrom, tbTo;
  1149. 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) &&
  1150. (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))
  1151. {
  1152. tmFrom.tm_year -= 1900;
  1153. tmFrom.tm_mon -= 1;
  1154. tbFrom.time = mktime(&tmFrom);
  1155. tmTo.tm_year -= 1900;
  1156. tmTo.tm_mon -= 1;
  1157. tbTo.time = mktime(&tmTo);
  1158. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1159. {
  1160. if(defaultTxProfile.ChargingProfileId == -1)
  1161. DEBUG_INFO("TxDefaultProfile found.\n");
  1162. else
  1163. DEBUG_INFO("TxDefaultProfile updated.\n");
  1164. // Required item
  1165. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1166. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1167. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1168. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1169. 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++)
  1170. {
  1171. 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"));
  1172. 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")));
  1173. 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?
  1174. 3:
  1175. 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")));
  1176. }
  1177. // Optional item
  1178. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1179. {
  1180. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1181. }
  1182. else
  1183. {
  1184. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1185. }
  1186. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1189. }
  1190. else
  1191. {
  1192. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1193. }
  1194. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1195. {
  1196. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1201. }
  1202. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1203. {
  1204. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1205. }
  1206. else
  1207. {
  1208. defaultTxProfile.TransactionId = -1;
  1209. }
  1210. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1211. {
  1212. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1213. }
  1214. else
  1215. {
  1216. defaultTxProfile.ChargingSchedule.Duration = -1;
  1217. }
  1218. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1219. {
  1220. 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")));
  1221. }
  1222. else
  1223. {
  1224. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1225. }
  1226. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1227. {
  1228. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1229. }
  1230. else
  1231. {
  1232. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. else
  1238. {
  1239. if(defaultTxProfile.ChargingProfileId == -1)
  1240. DEBUG_INFO("TxDefaultProfile found.\n");
  1241. else
  1242. DEBUG_INFO("TxDefaultProfile updated.\n");
  1243. // Required item
  1244. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1245. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1246. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1247. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1248. 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++)
  1249. {
  1250. 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"));
  1251. 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")));
  1252. 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?
  1253. 3:
  1254. 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")));
  1255. }
  1256. // Optional item
  1257. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1258. {
  1259. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1260. }
  1261. else
  1262. {
  1263. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1264. }
  1265. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1266. {
  1267. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1268. }
  1269. else
  1270. {
  1271. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1272. }
  1273. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1274. {
  1275. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1276. }
  1277. else
  1278. {
  1279. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1280. }
  1281. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1282. {
  1283. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1284. }
  1285. else
  1286. {
  1287. defaultTxProfile.TransactionId = -1;
  1288. }
  1289. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1290. {
  1291. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1292. }
  1293. else
  1294. {
  1295. defaultTxProfile.ChargingSchedule.Duration = -1;
  1296. }
  1297. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1298. {
  1299. 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")));
  1300. }
  1301. else
  1302. {
  1303. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1304. }
  1305. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1306. {
  1307. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1308. }
  1309. else
  1310. {
  1311. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. json_object_put(obj);
  1317. }
  1318. fclose(fp);
  1319. /*
  1320. if(defaultTxProfile.ChargingProfileId != -1)
  1321. {
  1322. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1323. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1324. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1325. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1326. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1327. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1328. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1329. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1330. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1331. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1332. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1333. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1334. {
  1335. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1336. {
  1337. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1338. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1339. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1340. }
  1341. }
  1342. }
  1343. else
  1344. DEBUG_INFO("TxDefaultProfile not found.\n");
  1345. DEBUG_INFO("------------------------------------\n");*/
  1346. }
  1347. // Search tx profile
  1348. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1349. if((access(profileFileName, F_OK))!=-1)
  1350. {
  1351. fp = fopen(profileFileName, "r");
  1352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1353. {
  1354. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1355. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1356. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1357. }
  1358. txProfile.ChargingProfileId = -1;
  1359. txProfile.StackLevel = -1;
  1360. while(getline(&line, &len, fp) != -1)
  1361. {
  1362. json_object *obj = NULL;
  1363. obj = json_tokener_parse(line);
  1364. if(is_error(obj))
  1365. {
  1366. DEBUG_ERROR("Parse txProfile from file error.\n");
  1367. }
  1368. else
  1369. {
  1370. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1371. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1372. )
  1373. {
  1374. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1375. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1376. )
  1377. {
  1378. struct tm tmFrom, tmTo;
  1379. struct timeb tbFrom, tbTo;
  1380. 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) &&
  1381. (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))
  1382. {
  1383. tmFrom.tm_year -= 1900;
  1384. tmFrom.tm_mon -= 1;
  1385. tbFrom.time = mktime(&tmFrom);
  1386. tmTo.tm_year -= 1900;
  1387. tmTo.tm_mon -= 1;
  1388. tbTo.time = mktime(&tmTo);
  1389. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1390. {
  1391. if(txProfile.ChargingProfileId == -1)
  1392. DEBUG_INFO("TxProfile found.\n");
  1393. else
  1394. DEBUG_INFO("TxProfile updated.\n");
  1395. // Required item
  1396. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1397. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1398. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1399. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1400. 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++)
  1401. {
  1402. 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"));
  1403. 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")));
  1404. 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?
  1405. 3:
  1406. 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")));
  1407. }
  1408. // Optional item
  1409. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1410. {
  1411. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1412. }
  1413. else
  1414. {
  1415. sprintf((char*)txProfile.ValidFrom, " ");
  1416. }
  1417. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1418. {
  1419. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1420. }
  1421. else
  1422. {
  1423. sprintf((char*)txProfile.ValidTo, " ");
  1424. }
  1425. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1426. {
  1427. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1428. }
  1429. else
  1430. {
  1431. sprintf((char*)txProfile.RecurrencyKind, " ");
  1432. }
  1433. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1434. {
  1435. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1436. }
  1437. else
  1438. {
  1439. txProfile.TransactionId = -1;
  1440. }
  1441. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1442. {
  1443. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1444. }
  1445. else
  1446. {
  1447. txProfile.ChargingSchedule.Duration = -1;
  1448. }
  1449. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1450. {
  1451. 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")));
  1452. }
  1453. else
  1454. {
  1455. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1456. }
  1457. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1458. {
  1459. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1460. }
  1461. else
  1462. {
  1463. txProfile.ChargingSchedule.MinChargingRate = -1;
  1464. }
  1465. }
  1466. }
  1467. }
  1468. else
  1469. {
  1470. if(txProfile.ChargingProfileId == -1)
  1471. DEBUG_INFO("TxProfile found.\n");
  1472. else
  1473. DEBUG_INFO("TxProfile updated.\n");
  1474. // Required item
  1475. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1476. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1477. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1478. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1479. 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++)
  1480. {
  1481. 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"));
  1482. 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")));
  1483. 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?
  1484. 3:
  1485. 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")));
  1486. }
  1487. // Optional item
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1489. {
  1490. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)txProfile.ValidFrom, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. {
  1498. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1499. }
  1500. else
  1501. {
  1502. sprintf((char*)txProfile.ValidTo, " ");
  1503. }
  1504. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1505. {
  1506. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1507. }
  1508. else
  1509. {
  1510. sprintf((char*)txProfile.RecurrencyKind, " ");
  1511. }
  1512. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1513. {
  1514. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1515. }
  1516. else
  1517. {
  1518. txProfile.TransactionId = -1;
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1521. {
  1522. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1523. }
  1524. else
  1525. {
  1526. txProfile.ChargingSchedule.Duration = -1;
  1527. }
  1528. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1529. {
  1530. 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")));
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1535. }
  1536. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1537. {
  1538. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1539. }
  1540. else
  1541. {
  1542. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. json_object_put(obj);
  1548. }
  1549. fclose(fp);
  1550. /*
  1551. if(defaultTxProfile.ChargingProfileId != -1)
  1552. {
  1553. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1554. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1555. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1556. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1557. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1558. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1559. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1560. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1561. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1562. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1563. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1564. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1565. {
  1566. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1567. {
  1568. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1569. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1570. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1571. }
  1572. }
  1573. }
  1574. else
  1575. DEBUG_INFO("TxProfile not found.\n");*/
  1576. }
  1577. /*
  1578. * Align found profile start schedule & periods
  1579. */
  1580. //DEBUG_INFO("====================================\n");
  1581. /*
  1582. // For local test usage, force modify found profile start schedule info
  1583. 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);
  1584. 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);
  1585. 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);
  1586. */
  1587. if(maxProfile.ChargingProfileId != -1)
  1588. {
  1589. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1590. {
  1591. if(maxProfile.ChargingSchedule.Duration != -1)
  1592. {
  1593. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1594. 0:
  1595. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1596. }
  1597. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1598. {
  1599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1600. {
  1601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1602. 0:
  1603. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1604. }
  1605. }
  1606. }
  1607. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1608. {
  1609. if(maxProfile.ChargingSchedule.Duration != -1)
  1610. {
  1611. 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?
  1612. 0:
  1613. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1614. }
  1615. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1616. {
  1617. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1618. {
  1619. 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?
  1620. 0:
  1621. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1622. }
  1623. }
  1624. }
  1625. else
  1626. {
  1627. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1628. {
  1629. if(maxProfile.ChargingSchedule.Duration != -1)
  1630. {
  1631. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1632. 0:
  1633. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1634. }
  1635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1636. {
  1637. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1638. {
  1639. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1640. 0:
  1641. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1642. }
  1643. }
  1644. }
  1645. else
  1646. {
  1647. if(maxProfile.ChargingSchedule.Duration != -1)
  1648. {
  1649. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1650. 0:
  1651. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1652. }
  1653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1654. {
  1655. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1656. {
  1657. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1658. 0:
  1659. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1660. }
  1661. }
  1662. }
  1663. }
  1664. /*
  1665. DEBUG_INFO("MaxProfile after align.\n");
  1666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1672. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1673. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1678. {
  1679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1680. {
  1681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1684. }
  1685. }
  1686. DEBUG_INFO("------------------------------------\n");*/
  1687. }
  1688. if(defaultTxProfile.ChargingProfileId != -1)
  1689. {
  1690. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1691. {
  1692. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1693. {
  1694. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1695. 0:
  1696. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1697. }
  1698. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1699. {
  1700. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1701. {
  1702. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1703. 0:
  1704. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1705. }
  1706. }
  1707. }
  1708. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1709. {
  1710. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1711. {
  1712. 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?
  1713. 0:
  1714. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1715. }
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1719. {
  1720. 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?
  1721. 0:
  1722. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1723. }
  1724. }
  1725. }
  1726. else
  1727. {
  1728. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1729. {
  1730. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1731. {
  1732. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1733. 0:
  1734. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1735. }
  1736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1737. {
  1738. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1739. {
  1740. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1741. 0:
  1742. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1743. }
  1744. }
  1745. }
  1746. else
  1747. {
  1748. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1749. {
  1750. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1751. 0:
  1752. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1753. }
  1754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1755. {
  1756. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1757. {
  1758. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1759. 0:
  1760. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1761. }
  1762. }
  1763. }
  1764. }
  1765. /*
  1766. DEBUG_INFO("defaultTxProfile after align.\n");
  1767. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1768. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1769. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1770. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1771. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1772. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1773. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1774. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1775. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1776. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1777. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1778. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1779. {
  1780. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1781. {
  1782. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1783. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1784. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1785. }
  1786. }
  1787. DEBUG_INFO("------------------------------------\n");*/
  1788. }
  1789. if(txProfile.ChargingProfileId != -1)
  1790. {
  1791. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1792. {
  1793. if(txProfile.ChargingSchedule.Duration != -1)
  1794. {
  1795. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1796. 0:
  1797. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1798. }
  1799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1800. {
  1801. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1802. {
  1803. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1804. 0:
  1805. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1806. }
  1807. }
  1808. }
  1809. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1810. {
  1811. if(txProfile.ChargingSchedule.Duration != -1)
  1812. {
  1813. 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?
  1814. 0:
  1815. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1816. }
  1817. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1818. {
  1819. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1820. {
  1821. 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?
  1822. 0:
  1823. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1824. }
  1825. }
  1826. }
  1827. else
  1828. {
  1829. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1830. {
  1831. if(txProfile.ChargingSchedule.Duration != -1)
  1832. {
  1833. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1834. 0:
  1835. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1836. }
  1837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1838. {
  1839. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1840. {
  1841. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1842. 0:
  1843. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1844. }
  1845. }
  1846. }
  1847. else
  1848. {
  1849. if(txProfile.ChargingSchedule.Duration != -1)
  1850. {
  1851. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1852. 0:
  1853. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1854. }
  1855. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1856. {
  1857. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1858. {
  1859. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1860. 0:
  1861. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1862. }
  1863. }
  1864. }
  1865. }
  1866. /*
  1867. DEBUG_INFO("txProfile after align.\n");
  1868. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1869. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1870. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1871. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1872. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1873. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1874. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1875. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1876. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1877. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1878. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1879. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1880. {
  1881. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1882. {
  1883. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1884. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1885. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1886. }
  1887. }*/
  1888. }
  1889. /*
  1890. * Merge to conposite schedule
  1891. */
  1892. //DEBUG_INFO("====================================\n");
  1893. // Find each profile period quantity
  1894. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1895. {
  1896. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1897. limitMax = idx+1;
  1898. }
  1899. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1900. {
  1901. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1902. limitDef = idx+1;
  1903. }
  1904. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1905. {
  1906. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1907. limitTx = idx+1;
  1908. }
  1909. // TxProfile found, composite schedule based on it
  1910. if(txProfile.ChargingProfileId != -1)
  1911. {
  1912. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1913. {
  1914. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1915. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1916. {
  1917. if(maxProfile.ChargingProfileId != -1)
  1918. {
  1919. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1920. {
  1921. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1922. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1923. {
  1924. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1925. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1926. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1927. }
  1928. if(idxMaxPeriod == (limitMax-1))
  1929. {
  1930. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1931. {
  1932. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1933. {
  1934. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1935. compositePeriodIdx++;
  1936. }
  1937. else
  1938. {
  1939. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1940. }
  1941. }
  1942. }
  1943. }
  1944. }
  1945. else
  1946. {
  1947. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1948. {
  1949. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1950. compositePeriodIdx++;
  1951. }
  1952. else
  1953. {
  1954. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1955. }
  1956. }
  1957. }
  1958. if(idxTxPeriod == (limitTx-1))
  1959. {
  1960. if(defaultTxProfile.ChargingProfileId != -1)
  1961. {
  1962. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1963. {
  1964. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1965. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1966. {
  1967. if(maxProfile.ChargingProfileId != -1)
  1968. {
  1969. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1970. {
  1971. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1972. {
  1973. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1974. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1975. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1976. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1977. {
  1978. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1979. {
  1980. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1981. compositePeriodIdx++;
  1982. }
  1983. else
  1984. {
  1985. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1986. }
  1987. }
  1988. break;
  1989. }
  1990. }
  1991. }
  1992. else
  1993. {
  1994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1995. {
  1996. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1997. compositePeriodIdx++;
  1998. }
  1999. else
  2000. {
  2001. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2011. else if(defaultTxProfile.ChargingProfileId != -1)
  2012. {
  2013. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2014. {
  2015. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2016. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  2017. {
  2018. if(maxProfile.ChargingProfileId != -1)
  2019. {
  2020. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2021. {
  2022. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2023. {
  2024. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2025. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2026. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2027. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2028. {
  2029. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2030. {
  2031. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2032. compositePeriodIdx++;
  2033. }
  2034. else
  2035. {
  2036. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2037. }
  2038. }
  2039. break;
  2040. }
  2041. }
  2042. }
  2043. else
  2044. {
  2045. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2046. {
  2047. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2048. compositePeriodIdx++;
  2049. }
  2050. else
  2051. {
  2052. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2053. }
  2054. }
  2055. }
  2056. }
  2057. }
  2058. // Fill other period by MaxProfile
  2059. if(maxProfile.ChargingProfileId != -1)
  2060. {
  2061. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2062. {
  2063. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2064. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2065. {
  2066. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2067. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2068. {
  2069. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2070. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2071. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2072. }
  2073. if(idxMaxPeriod == (limitMax-1))
  2074. {
  2075. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2076. {
  2077. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2078. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2079. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2080. }
  2081. if(tmpPeriod.Limit != -1)
  2082. {
  2083. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2084. {
  2085. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2086. {
  2087. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2088. compositePeriodIdx++;
  2089. }
  2090. else
  2091. {
  2092. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2101. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2102. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2103. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2104. {
  2105. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2106. {
  2107. compositeProfile->ChargingProfileId = 1;
  2108. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2109. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2110. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2111. }
  2112. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2113. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2114. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2115. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2116. }
  2117. if(line)
  2118. free(line);
  2119. }
  2120. //==========================================
  2121. // Init all share memory
  2122. //==========================================
  2123. int InitShareMemory()
  2124. {
  2125. int result = PASS;
  2126. int MeterSMId;
  2127. //creat ShmSysConfigAndInfo
  2128. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2129. {
  2130. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2131. result = FAIL;
  2132. }
  2133. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2134. {
  2135. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2136. result = FAIL;
  2137. }
  2138. else
  2139. {}
  2140. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2141. {
  2142. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2143. result = FAIL;
  2144. }
  2145. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2146. {
  2147. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2148. result = FAIL;
  2149. }
  2150. else
  2151. {}
  2152. //creat ShmPsuData
  2153. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2154. {
  2155. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2156. result = FAIL;
  2157. }
  2158. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2159. {
  2160. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2161. result = FAIL;
  2162. }
  2163. else
  2164. {}
  2165. //creat ShmOCPP16Data
  2166. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2167. {
  2168. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2169. result = FAIL;
  2170. }
  2171. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2172. {
  2173. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2174. result = FAIL;
  2175. }
  2176. else
  2177. {}
  2178. /****************************** For Initial Settings************************************************/
  2179. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2180. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2181. // allocate Configuration memory address
  2182. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2183. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2184. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2185. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2186. //offline MeterValue Interval
  2187. TempMeterValueInterval = 0;
  2188. return result;
  2189. }
  2190. int ProcessShareMemory()
  2191. {
  2192. if(InitShareMemory() == FAIL)
  2193. {
  2194. DEBUG_ERROR("InitShareMemory NG\n");
  2195. if(ShmStatusCodeData!=NULL)
  2196. {
  2197. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2198. }
  2199. sleep(5);
  2200. return FAIL;
  2201. }
  2202. return PASS;
  2203. }
  2204. //---------------------common routine---------------------------//
  2205. int isOFFline(void)
  2206. {
  2207. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2208. {
  2209. if(TempMeterValueInterval >= 2 )
  2210. {
  2211. TempMeterValueInterval = 0;
  2212. return TRUE;
  2213. }
  2214. else
  2215. {
  2216. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2217. return FALSE;
  2218. }
  2219. }
  2220. else
  2221. {
  2222. return FALSE;
  2223. }
  2224. }
  2225. //---------------------------------------------
  2226. // new:
  2227. // enum SYSTEM_STATUS
  2228. // {
  2229. // SYS_MODE_BOOTING = 0,
  2230. // SYS_MODE_IDLE = 1,
  2231. // SYS_MODE_AUTHORIZING = 2,
  2232. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2233. // SYS_MODE_REASSIGN = 4,
  2234. // SYS_MODE_PREPARING = 5,
  2235. // SYS_MODE_PREPARE_FOR_EV = 6,
  2236. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2237. // SYS_MODE_CHARGING = 8,
  2238. // SYS_MODE_TERMINATING = 9,
  2239. // SYS_MODE_COMPLETE = 10,
  2240. // SYS_MODE_ALARM = 11,
  2241. // SYS_MODE_FAULT = 12,
  2242. // SYS_MODE_RESERVATION = 13,
  2243. // SYS_MODE_BOOKING = 14,
  2244. // SYS_MODE_MAINTAIN = 15,
  2245. // SYS_MODE_DEBUG = 16,
  2246. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2247. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2248. // SYS_MODE_UPDATE = 19
  2249. // };
  2250. //
  2251. //
  2252. //-----------------------------------------
  2253. void CheckSystemValue(void)
  2254. {
  2255. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2256. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2257. char filenmae[100]={0};
  2258. char str[100]={0};
  2259. int tempIndex = 0;
  2260. //===============================
  2261. // send Heartbeat
  2262. //===============================
  2263. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2264. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2265. {
  2266. clientTime.Heartbeat=time((time_t*)NULL);
  2267. if(server_sign == TRUE)
  2268. {
  2269. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2270. }
  2271. else
  2272. {
  2273. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2274. }
  2275. }
  2276. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2277. {
  2278. //parameter for test
  2279. sendHeartbeatRequest(0);
  2280. //==============================================
  2281. // Reset Waiting Time
  2282. //==============================================
  2283. clientTime.Heartbeat=time((time_t*)NULL);
  2284. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2285. }
  2286. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2287. {
  2288. //===============================
  2289. // CSU Trigger Reset Conf
  2290. //===============================
  2291. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2292. {
  2293. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2294. }
  2295. //===============================
  2296. // CSU Trigger Authorize Request
  2297. //===============================
  2298. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2299. {
  2300. sendAuthorizeRequest(0);
  2301. authorizeRetryTimes = authorizeRetryTimes + 1;
  2302. if(authorizeRetryTimes < 3)
  2303. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2304. }
  2305. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2306. {
  2307. authorizeRetryTimes = 0;
  2308. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2309. server_sign = FALSE;
  2310. }
  2311. 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))
  2312. {
  2313. sendAuthorizeRequest(0);
  2314. }
  2315. //===============================
  2316. // CSU Trigger Smart Charging Profilw
  2317. //===============================
  2318. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2319. {
  2320. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2321. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2322. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2323. }
  2324. //==============================================
  2325. // Charger start transaction
  2326. //==============================================
  2327. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2328. {
  2329. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2330. sendStartTransactionRequest(gun_index);
  2331. clientTime.StartTransaction = time((time_t*)NULL);
  2332. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2333. }
  2334. //==============================================
  2335. // Charger stop transaction
  2336. //==============================================
  2337. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2338. {
  2339. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2340. sendStopTransactionRequest(gun_index);
  2341. clientTime.StopTransaction = time((time_t*)NULL);
  2342. }
  2343. //==============================================
  2344. // Charger status report
  2345. //==============================================
  2346. //--- Check Mode Change ---//
  2347. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2348. if(gunType[gun_index] == 'J')
  2349. {
  2350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2351. {
  2352. tempIndex = ((gun_index==2) ? 1: 0);
  2353. }
  2354. else
  2355. {
  2356. tempIndex = gun_index;
  2357. }
  2358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2359. {
  2360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2361. {
  2362. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[gun_index]) )
  2363. {
  2364. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2365. ChademoPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2366. ChademoPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2367. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2368. statusModeChage[gun_index] = TRUE;
  2369. }
  2370. #if 1 // for TempStopTransaction
  2371. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2372. {
  2373. checkTempStopTransaction(gun_index);
  2374. }
  2375. #endif
  2376. }
  2377. }
  2378. }
  2379. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2380. {
  2381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2382. {
  2383. tempIndex = ((gun_index==2) ? 1: 0);
  2384. }
  2385. else
  2386. {
  2387. tempIndex = gun_index;
  2388. }
  2389. for (int index = 0; index < CCS_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2392. {
  2393. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[gun_index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2394. {
  2395. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2396. CcsPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2397. CcsPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2398. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2399. statusModeChage[gun_index] = TRUE;
  2400. }
  2401. #if 1 // for TempStopTransaction
  2402. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2403. {
  2404. checkTempStopTransaction(gun_index);
  2405. }
  2406. #endif
  2407. }
  2408. }
  2409. }
  2410. else if(gunType[gun_index] == 'G')
  2411. {
  2412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2413. {
  2414. tempIndex = ((gun_index==2) ? 1: 0);
  2415. }
  2416. else
  2417. {
  2418. tempIndex = gun_index;
  2419. }
  2420. for (int index = 0; index < GB_QUANTITY; index++)
  2421. {
  2422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2423. {
  2424. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[gun_index]) )
  2425. {
  2426. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2427. GbPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2428. GbPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2429. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2430. statusModeChage[gun_index] = TRUE;
  2431. }
  2432. #if 1 // for TempStopTransaction
  2433. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2434. {
  2435. checkTempStopTransaction(gun_index);
  2436. }
  2437. #endif
  2438. }
  2439. }
  2440. }
  2441. else
  2442. {
  2443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2444. {
  2445. tempIndex = 2;
  2446. }
  2447. else
  2448. {
  2449. tempIndex = gun_index;
  2450. }
  2451. for (int index = 0; index < AC_QUANTITY; index++)
  2452. {
  2453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2454. {
  2455. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[gun_index]) )
  2456. {
  2457. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2458. AcPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2459. AcPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2460. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2461. statusModeChage[gun_index] = TRUE;
  2462. }
  2463. #if 1 // for TempStopTransaction
  2464. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2465. {
  2466. checkTempStopTransaction(gun_index);
  2467. }
  2468. #endif
  2469. }
  2470. }// END
  2471. }
  2472. if(isWebsocketSendable &&
  2473. (((server_sign == TRUE) && (SystemInitial > 0)) ||
  2474. ((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))))) )
  2475. {
  2476. if(SystemInitial > 0)
  2477. SystemInitial = SystemInitial -1;
  2478. sendStatusNotificationRequest(gun_index);
  2479. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2480. statusModeChage[gun_index] = FALSE;
  2481. }
  2482. //==============================================
  2483. // Meter report
  2484. //==============================================
  2485. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) ||
  2486. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2487. {
  2488. //check Transaction active
  2489. if(gunType[gun_index] == 'J')
  2490. {
  2491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2492. {
  2493. tempIndex = ((gun_index==2) ? 1: 0);
  2494. }
  2495. else
  2496. {
  2497. tempIndex = gun_index;
  2498. }
  2499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2500. {
  2501. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2502. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2503. {
  2504. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2505. {
  2506. reqSampleMeter[gun_index] = 1;
  2507. }
  2508. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2509. {
  2510. reqClockAlignMeter[gun_index] = 1;
  2511. }
  2512. }
  2513. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2514. {
  2515. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2516. if((access(filenmae,F_OK))!=-1)
  2517. {
  2518. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2519. sprintf(str,"rm -f %s",filenmae);
  2520. system(str);
  2521. }
  2522. }
  2523. }// End for CHAdeMO
  2524. }
  2525. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2526. {
  2527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2528. {
  2529. tempIndex = ((gun_index==2) ? 1: 0);
  2530. }
  2531. else
  2532. {
  2533. tempIndex = gun_index;
  2534. }
  2535. for (int index = 0; index < CCS_QUANTITY; index++)
  2536. {
  2537. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2538. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2539. {
  2540. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2541. {
  2542. reqSampleMeter[gun_index] = 1;
  2543. }
  2544. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2545. {
  2546. reqClockAlignMeter[gun_index] = 1;
  2547. }
  2548. }
  2549. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2550. {
  2551. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2552. if((access(filenmae,F_OK))!=-1)
  2553. {
  2554. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2555. sprintf(str,"rm -f %s",filenmae);
  2556. system(str);
  2557. }
  2558. }
  2559. } // End for CCS
  2560. }
  2561. else if(gunType[gun_index] == 'G')
  2562. {
  2563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2564. {
  2565. tempIndex = ((gun_index==2) ? 1: 0);
  2566. }
  2567. else
  2568. {
  2569. tempIndex = gun_index;
  2570. }
  2571. for (int index = 0; index < GB_QUANTITY; index++)
  2572. {
  2573. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2574. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2575. {
  2576. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2577. {
  2578. reqSampleMeter[gun_index] = 1;
  2579. }
  2580. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2581. {
  2582. reqClockAlignMeter[gun_index] = 1;
  2583. }
  2584. }
  2585. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2586. {
  2587. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2588. if((access(filenmae,F_OK))!=-1)
  2589. {
  2590. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2591. sprintf(str,"rm -f %s",filenmae);
  2592. system(str);
  2593. }
  2594. }
  2595. }// End for GB
  2596. }
  2597. else
  2598. {
  2599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2600. {
  2601. tempIndex = 2;
  2602. }
  2603. else
  2604. {
  2605. tempIndex = gun_index;
  2606. }
  2607. for (int index = 0; index < AC_QUANTITY; index++)
  2608. {
  2609. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2610. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2611. {
  2612. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2613. {
  2614. reqSampleMeter[gun_index] = 1;
  2615. }
  2616. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2617. {
  2618. reqClockAlignMeter[gun_index] = 1;
  2619. }
  2620. }
  2621. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2622. {
  2623. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2624. if((access(filenmae,F_OK))!=-1)
  2625. {
  2626. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2627. sprintf(str,"rm -f %s",filenmae);
  2628. system(str);
  2629. }
  2630. }
  2631. }//End for AC
  2632. }
  2633. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2634. if(reqSampleMeter[gun_index] == 1)
  2635. {
  2636. sendMeterValuesRequest(gun_index);
  2637. storeTempStopTransaction(gun_index);
  2638. }
  2639. else if(reqClockAlignMeter[gun_index] == 1)
  2640. {
  2641. sendMeterValuesRequest(gun_index);
  2642. }
  2643. sleep(1);
  2644. }
  2645. //==============================================
  2646. // Check Connector reserved
  2647. //==============================================
  2648. //===============================
  2649. // Check if Reserve is expired
  2650. //===============================
  2651. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2652. {
  2653. double diff_t;
  2654. struct tm tp;
  2655. // current time
  2656. time_t t = time(NULL);
  2657. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2658. tp.tm_isdst = -1;
  2659. time_t utc = mktime(&tp);
  2660. diff_t = difftime(utc, t);
  2661. if(diff_t <= 0)
  2662. {
  2663. DEBUG_INFO("reserve expired.\n");
  2664. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2665. }
  2666. }//END OF Check if Reserve is expired
  2667. //==========================================
  2668. // csu trigger FirmwareStatusNotificationReq
  2669. //==========================================
  2670. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2671. {
  2672. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2673. }
  2674. //==========================================
  2675. // csu trigger CancelReservationConf
  2676. //==========================================
  2677. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2678. {
  2679. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2680. }
  2681. //==========================================
  2682. // csu trigger ChangeAvailabilityConf
  2683. //==========================================
  2684. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2685. {
  2686. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2687. }
  2688. //==========================================
  2689. // csu trigger UnlockConnectorConf
  2690. //==========================================
  2691. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2692. {
  2693. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2694. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2695. }
  2696. //==========================================
  2697. // csu trigger ReserveNowConf
  2698. //==========================================
  2699. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2700. {
  2701. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2702. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2703. }
  2704. //==========================================
  2705. // csu trigger DataTransferReq
  2706. //==========================================
  2707. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2708. {
  2709. sendDataTransferRequest(gun_index);
  2710. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2711. }
  2712. }
  2713. }
  2714. //==========================================
  2715. // send request routine
  2716. //==========================================
  2717. int sendAuthorizeRequest(int gun_index)
  2718. {
  2719. mtrace();
  2720. int result = FAIL;
  2721. char message[100]={0};
  2722. char guid[37];
  2723. char tempdata[65]={0};
  2724. DEBUG_INFO("sendAuthorizeRequest...\n");
  2725. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2726. //Local Authorize
  2727. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2728. {
  2729. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2730. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2731. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2732. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2733. result = PASS;
  2734. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2735. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2736. authorizeRetryTimes = 0;
  2737. return result;
  2738. }
  2739. 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))||
  2740. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2741. {
  2742. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2743. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2744. {
  2745. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2746. {
  2747. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2748. }
  2749. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2750. {
  2751. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2752. }
  2753. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2754. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2755. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2756. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2757. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2758. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2759. authorizeRetryTimes = 0;
  2760. return result;
  2761. }
  2762. else
  2763. {
  2764. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2768. result = PASS;
  2769. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2770. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2771. authorizeRetryTimes = 0;
  2772. return result;
  2773. }
  2774. }
  2775. //initailize struct Authorize
  2776. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2777. //get data from shared memory
  2778. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2779. random_uuid(guid);
  2780. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2781. LWS_Send(message);
  2782. sprintf(tempdata, "Authorize,%d", gun_index);
  2783. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2784. {
  2785. result = PASS;
  2786. DEBUG_INFO("Authorize mapItem pass\n");
  2787. }
  2788. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2789. return result;
  2790. }
  2791. int sendBootNotificationRequest(void)
  2792. {
  2793. mtrace();
  2794. int result = FAIL;
  2795. char message[500]={0}, payload[700]={0};
  2796. char guid[37]={0};
  2797. char tempdata[65]={0};
  2798. int IsGunCharging = FALSE;
  2799. //check Transaction active
  2800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2801. {
  2802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2803. {
  2804. IsGunCharging = TRUE;
  2805. }
  2806. }
  2807. for (int index = 0; index < CCS_QUANTITY; index++)
  2808. {
  2809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2810. {
  2811. IsGunCharging = TRUE;
  2812. }
  2813. }
  2814. for (int index = 0; index < GB_QUANTITY; index++)
  2815. {
  2816. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2817. {
  2818. IsGunCharging = TRUE;
  2819. }
  2820. }
  2821. for (int index = 0; index < AC_QUANTITY; index++)
  2822. {
  2823. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2824. {
  2825. IsGunCharging = TRUE;
  2826. }
  2827. }
  2828. if(IsGunCharging == TRUE)
  2829. {
  2830. server_sign = TRUE;
  2831. return result;
  2832. }
  2833. // Fill BootNotification fields
  2834. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2835. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2836. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2837. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2838. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2839. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2840. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2841. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2842. ShmOCPP16Data->ChargeBoxId
  2843. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2844. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2845. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2846. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2847. ,ShmOCPP16Data->BootNotification.CpIccid
  2848. ,ShmOCPP16Data->BootNotification.CpImsi);
  2849. random_uuid(guid);
  2850. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2851. LWS_Send(message);
  2852. sprintf(tempdata, "BootNotification,0");
  2853. 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*/)
  2854. {
  2855. result = PASS;
  2856. }
  2857. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2858. strcpy(queuedata,message);
  2859. return result;
  2860. }
  2861. int sendDataTransferRequest(int gun_index)
  2862. {
  2863. mtrace();
  2864. char message[1000]={0};
  2865. char guid[37]={0};
  2866. char tempdata[65]={0};
  2867. int result = FAIL;
  2868. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2869. random_uuid(guid);
  2870. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2871. MESSAGE_TYPE_CALL,
  2872. guid,
  2873. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2874. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2875. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2876. LWS_Send(message);
  2877. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2878. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2879. {
  2880. result = PASS;
  2881. DEBUG_INFO("DataTransfer mapItem pass\n");
  2882. }
  2883. return result;
  2884. }
  2885. int sendDiagnosticsStatusNotificationRequest(char *status)
  2886. {
  2887. mtrace();
  2888. int result = FAIL;
  2889. char message[110]={0};
  2890. char guid[37]={0};
  2891. char tempdata[65]={0};
  2892. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2893. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2894. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2895. random_uuid(guid);
  2896. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2897. LWS_Send(message);
  2898. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2899. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2900. {
  2901. result = PASS;
  2902. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2903. }
  2904. //#ifdef SystemLogMessage
  2905. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2906. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2907. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2908. //#endif
  2909. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2910. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2911. //record status
  2912. if(strcmp(status,"Idle")==0)
  2913. {
  2914. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2915. }
  2916. else if(strcmp(status,"Uploaded")==0)
  2917. {
  2918. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2919. }
  2920. else if(strcmp(status,"UploadFailed")==0)
  2921. {
  2922. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2923. }
  2924. else if(strcmp(status,"Uploading")==0)
  2925. {
  2926. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2927. }
  2928. return result;
  2929. }
  2930. int sendFirmwareStatusNotificationRequest(char *status)
  2931. {
  2932. mtrace();
  2933. int result = FAIL;
  2934. char message[110]={0};
  2935. char guid[37]={0};
  2936. char tempdata[65]={0};
  2937. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2938. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2939. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2940. random_uuid(guid);
  2941. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2942. LWS_Send(message);
  2943. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2944. 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*/)
  2945. {
  2946. result = PASS;
  2947. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2948. }
  2949. //#ifdef SystemLogMessage
  2950. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2951. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2952. //#endif
  2953. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2954. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2955. //record status
  2956. if(strcmp(status,"Downloaded")==0)
  2957. {
  2958. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2959. }
  2960. else if(strcmp(status,"DownloadFailed")==0)
  2961. {
  2962. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2963. }
  2964. else if(strcmp(status,"Downloading")==0)
  2965. {
  2966. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2967. }
  2968. else if(strcmp(status,"Idle")==0)
  2969. {
  2970. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2971. }
  2972. else if(strcmp(status,"InstallationFailed")==0)
  2973. {
  2974. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2975. }
  2976. else if(strcmp(status,"Installing")==0)
  2977. {
  2978. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2979. }
  2980. else if(strcmp(status,"Installed")==0)
  2981. {
  2982. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2983. }
  2984. return result;
  2985. }
  2986. int sendHeartbeatRequest(int gun_index)
  2987. {
  2988. mtrace();
  2989. int result = FAIL;
  2990. char message[80]={0};
  2991. char guid[37]={0};
  2992. char tempdata[65]={0};
  2993. random_uuid(guid);
  2994. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2995. , MESSAGE_TYPE_CALL
  2996. , guid );
  2997. LWS_Send(message);
  2998. sprintf(tempdata, "Heartbeat,%d", 0);
  2999. 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*/)
  3000. {
  3001. result = PASS;
  3002. }
  3003. return result;
  3004. }
  3005. int sendStartTransactionRequest(int gun_index)
  3006. {
  3007. mtrace();
  3008. int result = FAIL;
  3009. char message[250]={0};
  3010. char guid[37]={0};
  3011. struct timeval tmnow;
  3012. struct tm *tm;
  3013. char buf[28];//, usec_buf[6];
  3014. char tempdata[65]={0};
  3015. int tempIndex = 0;
  3016. DEBUG_INFO("sendStartTransactionRequest...\n");
  3017. gettimeofday(&tmnow, NULL);
  3018. time_t t;
  3019. t = time(NULL);
  3020. /*UTC time and date*/
  3021. tm = gmtime(&t);
  3022. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3023. #if 0 // remove temporally
  3024. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3025. strcat(buf,".");
  3026. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3027. strcat(buf,usec_buf);
  3028. #endif
  3029. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3030. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3031. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3032. // clear StartTransaction Response
  3033. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3034. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3035. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3036. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3037. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3038. if(gunType[gun_index] == 'J')
  3039. {
  3040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3041. {
  3042. tempIndex = ((gun_index==2) ? 1: 0);
  3043. }
  3044. else
  3045. {
  3046. tempIndex = gun_index;
  3047. }
  3048. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3049. {
  3050. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3051. {
  3052. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  3053. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3054. }
  3055. }
  3056. }
  3057. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3058. {
  3059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3060. {
  3061. tempIndex = ((gun_index==2) ? 1: 0);
  3062. }
  3063. else
  3064. {
  3065. tempIndex = gun_index;
  3066. }
  3067. for (int index = 0; index < CCS_QUANTITY; index++)
  3068. {
  3069. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3070. {
  3071. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  3072. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3073. }
  3074. }
  3075. }
  3076. else if(gunType[gun_index] == 'G')
  3077. {
  3078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3079. {
  3080. tempIndex = ((gun_index==2) ? 1: 0);
  3081. }
  3082. else
  3083. {
  3084. tempIndex = gun_index;
  3085. }
  3086. for (int index = 0; index < GB_QUANTITY; index++)
  3087. {
  3088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3089. {
  3090. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  3091. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3092. }
  3093. }
  3094. }
  3095. else
  3096. {
  3097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3098. {
  3099. tempIndex = 2;
  3100. }
  3101. else
  3102. {
  3103. tempIndex = gun_index;
  3104. }
  3105. for (int index = 0; index < AC_QUANTITY; index++)
  3106. {
  3107. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3108. {
  3109. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3110. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3111. }
  3112. }
  3113. }
  3114. random_uuid(guid);
  3115. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3116. {
  3117. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3118. , gun_index +1
  3119. , MESSAGE_TYPE_CALL
  3120. , guid
  3121. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3122. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3123. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3124. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3125. }
  3126. else
  3127. {
  3128. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3129. , gun_index +1
  3130. , MESSAGE_TYPE_CALL
  3131. , guid
  3132. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3133. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3134. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3135. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3136. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3137. }
  3138. #if 1
  3139. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3140. if(hashmap_operation(0, 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*/)
  3141. {
  3142. result = PASS;
  3143. }
  3144. #endif
  3145. strcpy(queuedata, message);
  3146. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3147. /*
  3148. if(GetTransactionQueueNum() == 1)
  3149. {
  3150. LWS_Send(message + 2);
  3151. }*/
  3152. return result;
  3153. }
  3154. int sendStatusNotificationRequest(int gun_index)
  3155. {
  3156. mtrace();
  3157. int result = FAIL;
  3158. char message[600]={0};
  3159. char guid[37];
  3160. int currentStatus = 0;
  3161. struct timeval tmnow;
  3162. struct tm *tm;
  3163. char buf[28];//, usec_buf[6];
  3164. char tempdata[65]={0};
  3165. int tempIndex = 0;
  3166. gettimeofday(&tmnow, NULL);
  3167. time_t t;
  3168. t = time(NULL);
  3169. /*UTC time and date*/
  3170. tm = gmtime(&t);
  3171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3172. #if 0 // remove temporally
  3173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3174. strcat(buf,".");
  3175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3176. strcat(buf,usec_buf);
  3177. #endif
  3178. printf("%s",buf);
  3179. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3180. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3181. // it's option
  3182. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3183. /*
  3184. enum _SYSTEM_STATUS
  3185. {
  3186. S_BOOTING = 0,
  3187. S_IDLE, = 1
  3188. S_AUTHORIZING, =2
  3189. S_REASSIGN_CHECK, =3
  3190. S_REASSIGN, =4
  3191. S_PRECHARGE, =5
  3192. S_PREPARING_FOR_EV, =6
  3193. S_PREPARING_FOR_EVSE, =7
  3194. S_CHARGING, =8
  3195. S_TERMINATING, =9
  3196. S_COMPLETE, =10
  3197. S_ALARM, =11
  3198. S_FAULT =12
  3199. }
  3200. */
  3201. //check Transaction active
  3202. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3203. if(gunType[gun_index] == 'J')
  3204. {
  3205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3206. {
  3207. tempIndex = ((gun_index==2) ? 1: 0);
  3208. }
  3209. else
  3210. {
  3211. tempIndex = gun_index;
  3212. }
  3213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3214. {
  3215. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3216. {
  3217. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3218. {
  3219. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3220. {
  3221. currentStatus = 1; //OCPP Status: Preparing
  3222. }
  3223. else
  3224. {
  3225. currentStatus = 0; //OCPP Status: Available
  3226. }
  3227. }
  3228. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3229. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3230. ) //S_PRECHARGE
  3231. {
  3232. currentStatus = 1; //OCPP Status: Preparing
  3233. }
  3234. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3235. {
  3236. currentStatus = 2; //OCPP Status: Charging
  3237. }
  3238. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3239. {
  3240. currentStatus = 5; //OCPP Status: Finishing
  3241. }
  3242. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3243. {
  3244. currentStatus = 4; //OCPP Status: SuspendedEV
  3245. }
  3246. 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
  3247. {
  3248. currentStatus = 7; //OCPP Status: Unavailable
  3249. }
  3250. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3251. {
  3252. currentStatus = 8; //OCPP Status: Faulted
  3253. }
  3254. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3255. {
  3256. currentStatus = 6; //OCPP Status: Reserved
  3257. }
  3258. } //end of the same index
  3259. }//end of for CHAdeMO_QUANTITY
  3260. }
  3261. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3262. {
  3263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3264. {
  3265. tempIndex = ((gun_index==2) ? 1: 0);
  3266. }
  3267. else
  3268. {
  3269. tempIndex = gun_index;
  3270. }
  3271. for (int index = 0; index < CCS_QUANTITY; index++)
  3272. {
  3273. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3274. {
  3275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3276. {
  3277. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3278. {
  3279. currentStatus = 1; //OCPP Status: Preparing
  3280. }
  3281. else
  3282. {
  3283. currentStatus = 0; //OCPP Status: Available
  3284. }
  3285. }
  3286. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3287. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3288. ) //S_PRECHARGE
  3289. {
  3290. currentStatus = 1; //OCPP Status: Preparing
  3291. }
  3292. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3293. {
  3294. currentStatus = 2; //OCPP Status: Charging
  3295. }
  3296. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3297. {
  3298. currentStatus = 5; //OCPP Status: Finishing
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3301. {
  3302. currentStatus = 4; //OCPP Status: SuspendedEV
  3303. }
  3304. 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
  3305. {
  3306. currentStatus = 7; //OCPP Status : Unavailable
  3307. }
  3308. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3309. {
  3310. currentStatus = 8; //OCPP Status: Faulted
  3311. }
  3312. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3313. {
  3314. currentStatus = 6; //OCPP Status: Reserved
  3315. }
  3316. } //end of the same index
  3317. } // end of for CCS_QUANTITY
  3318. }
  3319. else if(gunType[gun_index] == 'G')
  3320. {
  3321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3322. {
  3323. tempIndex = ((gun_index==2) ? 1: 0);
  3324. }
  3325. else
  3326. {
  3327. tempIndex = gun_index;
  3328. }
  3329. for (int index = 0; index < GB_QUANTITY; index++)
  3330. {
  3331. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3332. {
  3333. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3334. {
  3335. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3336. {
  3337. currentStatus = 1; //OCPP Status: Preparing
  3338. }
  3339. else
  3340. {
  3341. currentStatus = 0; //OCPP Status: Available
  3342. }
  3343. }
  3344. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3345. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3346. ) //S_PRECHARGE
  3347. {
  3348. currentStatus = 1; //OCPP Status: Preparing
  3349. }
  3350. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3351. {
  3352. currentStatus = 2; //OCPP Status: Charging
  3353. }
  3354. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3355. {
  3356. currentStatus = 5; //OCPP Status: Finishing
  3357. }
  3358. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3359. {
  3360. currentStatus = 4; //OCPP Status: SuspendedEV
  3361. }
  3362. 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
  3363. {
  3364. currentStatus = 7; //OCPP Status: Unavailable
  3365. }
  3366. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3367. {
  3368. currentStatus = 8; //OCPP Status: Faulted
  3369. }
  3370. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3371. {
  3372. currentStatus = 6; //OCPP Status: Reserved
  3373. }
  3374. } //end of the same index
  3375. } // end of for GB_QUANTITY
  3376. }
  3377. else
  3378. {
  3379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3380. {
  3381. tempIndex = 2;
  3382. }
  3383. else
  3384. {
  3385. tempIndex = gun_index;
  3386. }
  3387. for (int index = 0; index < AC_QUANTITY; index++)
  3388. {
  3389. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3390. {
  3391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3392. {
  3393. 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))
  3394. {
  3395. currentStatus = 1; //OCPP Status: Preparing
  3396. }
  3397. else
  3398. {
  3399. currentStatus = 0; //OCPP Status: Available
  3400. }
  3401. }
  3402. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  3403. {
  3404. currentStatus = 1; //OCPP Status: Preparing
  3405. }
  3406. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3407. {
  3408. currentStatus = 2; //OCPP Status: Charging
  3409. }
  3410. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3411. {
  3412. currentStatus = 5; //OCPP Status: Finishing
  3413. }
  3414. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3415. {
  3416. currentStatus = 4; //OCPP Status: SuspendedEV
  3417. }
  3418. 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
  3419. {
  3420. currentStatus = 7; //OCPP Status: Unavailable
  3421. }
  3422. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3423. {
  3424. currentStatus = 8; //OCPP Status: Faulted
  3425. }
  3426. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3427. {
  3428. currentStatus = 6; //OCPP Status: Reserved
  3429. }
  3430. }//end of the same index
  3431. }//end of for AC_QUANTITY
  3432. }
  3433. //it's option
  3434. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3435. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3436. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3437. random_uuid(guid);
  3438. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3439. , MESSAGE_TYPE_CALL
  3440. , guid
  3441. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3442. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3443. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3444. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3445. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3446. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3447. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3448. LWS_Send(message);
  3449. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3450. if(hashmap_operation(0, 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*/)
  3451. {
  3452. //DEBUG_ERROR("statusNotification mapitem pass");
  3453. result = PASS;
  3454. }
  3455. return result;
  3456. }
  3457. int sendStopTransactionRequest(int gun_index)
  3458. {
  3459. mtrace();
  3460. int result = FAIL;
  3461. //char message[1500]={0};
  3462. char guid[37]={0};
  3463. char tempdata[65]={0};
  3464. int tempIndex = 0;
  3465. //int idx_sample=0;
  3466. DEBUG_ERROR("sendStopTransactionRequest \n");
  3467. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3468. //ENERGY_ACTIVE_IMPORT_REGISTER
  3469. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3470. if(gunType[gun_index] == 'J')
  3471. {
  3472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3473. {
  3474. tempIndex = ((gun_index==2) ? 1: 0);
  3475. }
  3476. else
  3477. {
  3478. tempIndex = gun_index;
  3479. }
  3480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3481. {
  3482. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3483. {
  3484. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3485. }
  3486. }// END OF CHAdeMO_QUANTITY
  3487. }
  3488. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3489. {
  3490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3491. {
  3492. tempIndex = ((gun_index==2) ? 1: 0);
  3493. }
  3494. else
  3495. {
  3496. tempIndex = gun_index;
  3497. }
  3498. for (int index = 0; index < CCS_QUANTITY; index++)
  3499. {
  3500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3501. {
  3502. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3503. }
  3504. }// END OF CCS_QUANTITY
  3505. }
  3506. else if(gunType[gun_index] == 'G')
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < GB_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3519. {
  3520. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3521. }
  3522. }// END OF GB_QUANTITY
  3523. }
  3524. else
  3525. {
  3526. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3527. {
  3528. tempIndex = 2;
  3529. }
  3530. else
  3531. {
  3532. tempIndex = gun_index;
  3533. }
  3534. for (int index = 0; index < AC_QUANTITY; index++)
  3535. {
  3536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3537. {
  3538. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3539. }
  3540. }// END OF AC_QUANTITY
  3541. }
  3542. //Stop Transaction Time
  3543. struct timeval tmnow;
  3544. struct tm *tm;
  3545. char buf[28];//, usec_buf[6];
  3546. gettimeofday(&tmnow, NULL);
  3547. time_t t;
  3548. t = time(NULL);
  3549. /*UTC time and date*/
  3550. tm = gmtime(&t);
  3551. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3553. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3554. random_uuid(guid);
  3555. /***********************************transactionData******************************************************/
  3556. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3558. //=================================
  3559. // Transaction_Begin
  3560. //=================================
  3561. // Energy.Active.Export.Interval
  3562. //idx_sample=0;
  3563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3566. 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*/]);
  3567. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3568. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3569. {
  3570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3571. }
  3572. else
  3573. {
  3574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3575. }
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3578. //=================================
  3579. // Transaction_End
  3580. //=================================
  3581. //Current.Export
  3582. //idx_sample=1;
  3583. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3584. if(gunType[gun_index] == 'J')
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3599. }
  3600. }// End of for CHAdeMO_QUANTITY
  3601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3602. }
  3603. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3604. {
  3605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3606. {
  3607. tempIndex = ((gun_index==2) ? 1: 0);
  3608. }
  3609. else
  3610. {
  3611. tempIndex = gun_index;
  3612. }
  3613. for (int index = 0; index < CCS_QUANTITY; index++)
  3614. {
  3615. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3616. {
  3617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3618. }
  3619. }// End of for CCS_QUANTITY
  3620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3621. }
  3622. else if(gunType[gun_index] == 'G')
  3623. {
  3624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3625. {
  3626. tempIndex = ((gun_index==2) ? 1: 0);
  3627. }
  3628. else
  3629. {
  3630. tempIndex = gun_index;
  3631. }
  3632. for (int index = 0; index < GB_QUANTITY; index++)
  3633. {
  3634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3635. {
  3636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3637. }
  3638. }// End of for GB_QUANTITY
  3639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3640. }
  3641. else
  3642. {
  3643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3644. {
  3645. tempIndex = 2;
  3646. }
  3647. else
  3648. {
  3649. tempIndex = gun_index;
  3650. }
  3651. for (int index = 0; index < AC_QUANTITY; index++)
  3652. {
  3653. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3654. {
  3655. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3656. }
  3657. }// End of for AC_QUANTITY
  3658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3659. }
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3663. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3666. //Energy.Active.Export.Interval
  3667. //idx_sample=2;
  3668. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3669. if(gunType[gun_index] == 'J')
  3670. {
  3671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3672. {
  3673. tempIndex = ((gun_index==2) ? 1: 0);
  3674. }
  3675. else
  3676. {
  3677. tempIndex = gun_index;
  3678. }
  3679. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3680. {
  3681. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3682. {
  3683. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3684. }
  3685. }// END OF CHAdeMO_QUANTITY
  3686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3687. }
  3688. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3689. {
  3690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3691. {
  3692. tempIndex = ((gun_index==2) ? 1: 0);
  3693. }
  3694. else
  3695. {
  3696. tempIndex = gun_index;
  3697. }
  3698. for (int index = 0; index < CCS_QUANTITY; index++)
  3699. {
  3700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3701. {
  3702. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3703. }
  3704. }// END OF CCS_QUANTITY
  3705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3706. }
  3707. else if(gunType[gun_index] == 'G')
  3708. {
  3709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3710. {
  3711. tempIndex = ((gun_index==2) ? 1: 0);
  3712. }
  3713. else
  3714. {
  3715. tempIndex = gun_index;
  3716. }
  3717. for (int index = 0; index < GB_QUANTITY; index++)
  3718. {
  3719. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3720. {
  3721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3722. }
  3723. }// END OF GB_QUANTITY
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3725. }
  3726. else
  3727. {
  3728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3729. {
  3730. tempIndex = 2;
  3731. }
  3732. else
  3733. {
  3734. tempIndex = gun_index;
  3735. }
  3736. for (int index = 0; index < AC_QUANTITY; index++)
  3737. {
  3738. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3739. {
  3740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3741. }
  3742. }// END OF AC_QUANTITY
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3744. }
  3745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3748. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3751. //Power.Active.Export
  3752. //idx_sample=3;
  3753. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3754. if(gunType[gun_index] == 'J')
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3757. {
  3758. tempIndex = ((gun_index==2) ? 1: 0);
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3765. {
  3766. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3767. {
  3768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3769. }
  3770. } // End for CHAdeMO_QUANTITY
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3772. }
  3773. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3774. {
  3775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3776. {
  3777. tempIndex = ((gun_index==2) ? 1: 0);
  3778. }
  3779. else
  3780. {
  3781. tempIndex = gun_index;
  3782. }
  3783. for (int index = 0; index < CCS_QUANTITY; index++)
  3784. {
  3785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3786. {
  3787. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3788. }
  3789. } // END for CCS_QUANTITY
  3790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3791. }
  3792. else if(gunType[gun_index] == 'G')
  3793. {
  3794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3795. {
  3796. tempIndex = ((gun_index==2) ? 1: 0);
  3797. }
  3798. else
  3799. {
  3800. tempIndex = gun_index;
  3801. }
  3802. for (int index = 0; index < GB_QUANTITY; index++)
  3803. {
  3804. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3805. {
  3806. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3807. }
  3808. }// END for GB_QUANTITY
  3809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3810. }
  3811. else
  3812. {
  3813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3814. {
  3815. tempIndex = 2;
  3816. }
  3817. else
  3818. {
  3819. tempIndex = gun_index;
  3820. }
  3821. for (int index = 0; index < AC_QUANTITY; index++)
  3822. {
  3823. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3824. {
  3825. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3826. }
  3827. } // END for AC_QUANTITY
  3828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3829. }
  3830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3833. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3836. //Voltage
  3837. //idx_sample=4;
  3838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3839. if(gunType[gun_index] == 'J')
  3840. {
  3841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3842. {
  3843. tempIndex = ((gun_index==2) ? 1: 0);
  3844. }
  3845. else
  3846. {
  3847. tempIndex = gun_index;
  3848. }
  3849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3850. {
  3851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3852. {
  3853. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3854. }
  3855. } // END OF FOR CHAdeMO_QUANTITY
  3856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3857. }
  3858. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3859. {
  3860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3861. {
  3862. tempIndex = ((gun_index==2) ? 1: 0);
  3863. }
  3864. else
  3865. {
  3866. tempIndex = gun_index;
  3867. }
  3868. for (int index = 0; index < CCS_QUANTITY; index++)
  3869. {
  3870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3871. {
  3872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3873. }
  3874. } // END OF FOR CCS_QUANTITY
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3876. }
  3877. else if(gunType[gun_index] == 'G')
  3878. {
  3879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3880. {
  3881. tempIndex = ((gun_index==2) ? 1: 0);
  3882. }
  3883. else
  3884. {
  3885. tempIndex = gun_index;
  3886. }
  3887. for (int index = 0; index < GB_QUANTITY; index++)
  3888. {
  3889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3890. {
  3891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3892. }
  3893. } // END OF FOR GB_QUANTITY
  3894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3895. }
  3896. else
  3897. {
  3898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3899. {
  3900. tempIndex = 2;
  3901. }
  3902. else
  3903. {
  3904. tempIndex = gun_index;
  3905. }
  3906. for (int index = 0; index < AC_QUANTITY; index++)
  3907. {
  3908. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3909. {
  3910. 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
  3911. }
  3912. } // END OF FOR AC_QUANTITY
  3913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3914. }
  3915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3918. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3921. //SoC
  3922. //idx_sample=5;
  3923. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3924. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3925. {
  3926. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3927. {
  3928. tempIndex = ((gun_index==2) ? 1: 0);
  3929. }
  3930. else
  3931. {
  3932. tempIndex = gun_index;
  3933. }
  3934. if(gunType[gun_index] == 'J')
  3935. {
  3936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3937. {
  3938. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3939. {
  3940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3941. }
  3942. }
  3943. }
  3944. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3945. {
  3946. for (int index = 0; index < CCS_QUANTITY; index++)
  3947. {
  3948. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3949. {
  3950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3951. }
  3952. }
  3953. }
  3954. else if(gunType[gun_index] == 'G')
  3955. {
  3956. for (int index = 0; index < GB_QUANTITY; index++)
  3957. {
  3958. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3959. {
  3960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3961. }
  3962. }
  3963. }
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3970. } // END FOR DC CASE
  3971. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3972. {
  3973. sprintf(queuedata,"%d,[%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\"}]}]}]"
  3974. ,gun_index+1
  3975. ,MESSAGE_TYPE_CALL
  3976. ,guid
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3982. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  4024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  4025. );
  4026. }
  4027. else
  4028. {
  4029. sprintf(queuedata,"%d,[%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\"}]}]}]"
  4030. ,gun_index+1
  4031. ,MESSAGE_TYPE_CALL
  4032. ,guid
  4033. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4034. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4035. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4037. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4038. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4046. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4047. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4048. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4049. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4050. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4074. );
  4075. }
  4076. #if 1 // for TempStopTransaction
  4077. //Delete TempStopTransaction
  4078. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4079. {
  4080. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4081. }
  4082. #endif
  4083. #if 1
  4084. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4085. if(hashmap_operation(0, guid, tempdata) == 1)
  4086. {
  4087. result = PASS;
  4088. DEBUG_INFO("StopTransaction mapitem pass\n");
  4089. }
  4090. #endif
  4091. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4092. /*
  4093. if(GetTransactionQueueNum() == 1)
  4094. {
  4095. LWS_Send(queuedata+2);
  4096. }*/
  4097. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4098. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4099. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  4100. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4101. {
  4102. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4103. }
  4104. //for test
  4105. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4106. return result;
  4107. }
  4108. int sendMeterValuesRequest(int gun_index)
  4109. {
  4110. mtrace();
  4111. int result = FAIL;
  4112. // char message[1500]={0};
  4113. char guid[37]={0};
  4114. //int idx_sample=0;
  4115. //int length = 0;
  4116. char tempdata[65]={0};
  4117. int tempIndex = 0;
  4118. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4119. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  4120. /*
  4121. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  4122. {
  4123. DEBUG_INFO("NOT SENT METER Vlaue\n");
  4124. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  4125. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  4126. return result;
  4127. }*/
  4128. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4129. {
  4130. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4131. }
  4132. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4133. //set value
  4134. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4135. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4136. random_uuid(guid);
  4137. //UTC Date time
  4138. struct timeval tmnow;
  4139. struct tm *tm;
  4140. char buf[28];//, usec_buf[6];
  4141. gettimeofday(&tmnow, NULL);
  4142. time_t t;
  4143. t = time(NULL);
  4144. /*UTC time and date*/
  4145. tm = gmtime(&t);
  4146. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4148. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4149. //idx_sample=0;
  4150. //********************************(1)Current.Export************************************************/
  4151. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4152. if(gunType[gun_index] == 'J')
  4153. {
  4154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4155. {
  4156. tempIndex = ((gun_index==2) ? 1: 0);
  4157. }
  4158. else
  4159. {
  4160. tempIndex = gun_index;
  4161. }
  4162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4163. {
  4164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4165. {
  4166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4167. }
  4168. }
  4169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4170. }
  4171. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4172. {
  4173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4174. {
  4175. tempIndex = ((gun_index==2) ? 1: 0);
  4176. }
  4177. else
  4178. {
  4179. tempIndex = gun_index;
  4180. }
  4181. for (int index = 0; index < CCS_QUANTITY; index++)
  4182. {
  4183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4184. {
  4185. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4186. }
  4187. }
  4188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4189. }
  4190. else if(gunType[gun_index] == 'G')
  4191. {
  4192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4193. {
  4194. tempIndex = ((gun_index==2) ? 1: 0);
  4195. }
  4196. else
  4197. {
  4198. tempIndex = gun_index;
  4199. }
  4200. for (int index = 0; index < GB_QUANTITY; index++)
  4201. {
  4202. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4203. {
  4204. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4205. }
  4206. }
  4207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4208. }
  4209. else
  4210. {
  4211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4212. {
  4213. tempIndex = 2;
  4214. }
  4215. else
  4216. {
  4217. tempIndex = gun_index;
  4218. }
  4219. for (int index = 0; index < AC_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4222. {
  4223. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4224. }
  4225. }
  4226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4227. }
  4228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4231. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4234. //idx_sample=1;
  4235. //********************************(2)Energy.Active.Import.Register ************************************************/
  4236. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4237. if(gunType[gun_index] == 'J')
  4238. {
  4239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4240. {
  4241. tempIndex = ((gun_index==2) ? 1: 0);
  4242. }
  4243. else
  4244. {
  4245. tempIndex = gun_index;
  4246. }
  4247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4248. {
  4249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4250. {
  4251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4252. }
  4253. }
  4254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4255. }
  4256. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4257. {
  4258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4259. {
  4260. tempIndex = ((gun_index==2) ? 1: 0);
  4261. }
  4262. else
  4263. {
  4264. tempIndex = gun_index;
  4265. }
  4266. for (int index = 0; index < CCS_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4269. {
  4270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4271. }
  4272. }
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4274. }
  4275. else if(gunType[gun_index] == 'G')
  4276. {
  4277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4278. {
  4279. tempIndex = ((gun_index==2) ? 1: 0);
  4280. }
  4281. else
  4282. {
  4283. tempIndex = gun_index;
  4284. }
  4285. for (int index = 0; index < GB_QUANTITY; index++)
  4286. {
  4287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4288. {
  4289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4290. }
  4291. }
  4292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4293. }
  4294. else
  4295. {
  4296. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4297. {
  4298. tempIndex = 2;
  4299. }
  4300. else
  4301. {
  4302. tempIndex = gun_index;
  4303. }
  4304. for (int index = 0; index < AC_QUANTITY; index++)
  4305. {
  4306. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4307. {
  4308. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4309. }
  4310. }
  4311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4312. }
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4316. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4319. //idx_sample=2;
  4320. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4321. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4322. if(gunType[gun_index] == 'J')
  4323. {
  4324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4325. {
  4326. tempIndex = ((gun_index==2) ? 1: 0);
  4327. }
  4328. else
  4329. {
  4330. tempIndex = gun_index;
  4331. }
  4332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4333. {
  4334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4335. {
  4336. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4337. }
  4338. } // END OF FOR CHAdeMO_QUANTITY
  4339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4340. }
  4341. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4342. {
  4343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4344. {
  4345. tempIndex = ((gun_index==2) ? 1: 0);
  4346. }
  4347. else
  4348. {
  4349. tempIndex = gun_index;
  4350. }
  4351. for (int index = 0; index < CCS_QUANTITY; index++)
  4352. {
  4353. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4354. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4355. {
  4356. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4357. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4358. }
  4359. } // END OF CCS_QUANTITY
  4360. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4361. }
  4362. else if(gunType[gun_index] == 'G')
  4363. {
  4364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4365. {
  4366. tempIndex = ((gun_index==2) ? 1: 0);
  4367. }
  4368. else
  4369. {
  4370. tempIndex = gun_index;
  4371. }
  4372. for (int index = 0; index < GB_QUANTITY; index++)
  4373. {
  4374. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4375. {
  4376. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4377. }
  4378. } // END OF GB_QUANTITY
  4379. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4380. }
  4381. else
  4382. {
  4383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4384. {
  4385. tempIndex = 2;
  4386. }
  4387. else
  4388. {
  4389. tempIndex = gun_index;
  4390. }
  4391. for (int index = 0; index < AC_QUANTITY; index++)
  4392. {
  4393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4394. {
  4395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4396. }
  4397. }
  4398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4399. }
  4400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4403. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4406. //idx_sample=3;
  4407. //********************************(4)Power.Active.Export************************************************/
  4408. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4409. if(gunType[gun_index] == 'J')
  4410. {
  4411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4412. {
  4413. tempIndex = ((gun_index==2) ? 1: 0);
  4414. }
  4415. else
  4416. {
  4417. tempIndex = gun_index;
  4418. }
  4419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4420. {
  4421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4422. {
  4423. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4424. }
  4425. } // END OF FOR
  4426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4427. }
  4428. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4429. {
  4430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4431. {
  4432. tempIndex = ((gun_index==2) ? 1: 0);
  4433. }
  4434. else
  4435. {
  4436. tempIndex = gun_index;
  4437. }
  4438. for (int index = 0; index < CCS_QUANTITY; index++)
  4439. {
  4440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4441. {
  4442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4443. }
  4444. }
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4446. }
  4447. else if(gunType[gun_index] == 'G')
  4448. {
  4449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4450. {
  4451. tempIndex = ((gun_index==2) ? 1: 0);
  4452. }
  4453. else
  4454. {
  4455. tempIndex = gun_index;
  4456. }
  4457. for (int index = 0; index < GB_QUANTITY; index++)
  4458. {
  4459. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4460. {
  4461. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4462. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4463. }
  4464. }
  4465. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4466. }
  4467. else
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4470. {
  4471. tempIndex = 2;
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < AC_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4480. {
  4481. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4482. }
  4483. }
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4489. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4492. //idx_sample=4;
  4493. //***********************************************(5)VOLTAGE******************************************************/
  4494. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4495. if(gunType[gun_index] == 'J')
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4498. {
  4499. tempIndex = ((gun_index==2) ? 1: 0);
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4506. {
  4507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4508. {
  4509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4510. }
  4511. }
  4512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4513. }
  4514. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4515. {
  4516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4517. {
  4518. tempIndex = ((gun_index==2) ? 1: 0);
  4519. }
  4520. else
  4521. {
  4522. tempIndex = gun_index;
  4523. }
  4524. for (int index = 0; index < CCS_QUANTITY; index++)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4527. {
  4528. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4529. }
  4530. }
  4531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4532. }
  4533. else if(gunType[gun_index] == 'G')
  4534. {
  4535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4536. {
  4537. tempIndex = ((gun_index==2) ? 1: 0);
  4538. }
  4539. else
  4540. {
  4541. tempIndex = gun_index;
  4542. }
  4543. for (int index = 0; index < GB_QUANTITY; index++)
  4544. {
  4545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4546. {
  4547. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4548. }
  4549. }
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4551. }
  4552. else
  4553. {
  4554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4555. {
  4556. tempIndex = 2;
  4557. }
  4558. else
  4559. {
  4560. tempIndex = gun_index;
  4561. }
  4562. for (int index = 0; index < AC_QUANTITY; index++)
  4563. {
  4564. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4565. {
  4566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4567. }
  4568. }
  4569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4570. }
  4571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4574. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4577. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4578. {
  4579. //idx_sample=5;
  4580. //sampledValue = NULL;
  4581. //***********************************************(6)SOC******************************************************/
  4582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4583. {
  4584. tempIndex = ((gun_index==2) ? 1: 0);
  4585. }
  4586. else
  4587. {
  4588. tempIndex = gun_index;
  4589. }
  4590. if(gunType[gun_index] == 'J')
  4591. {
  4592. //tempIndex = ((gun_index==2) ? 1: 0);
  4593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4594. {
  4595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4596. {
  4597. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4598. }
  4599. }
  4600. }
  4601. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4602. {
  4603. //tempIndex = ((gun_index==2) ? 1: 0);
  4604. for (int index = 0; index < CCS_QUANTITY; index++)
  4605. {
  4606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4607. {
  4608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4609. }
  4610. }
  4611. }
  4612. else if(gunType[gun_index] == 'G')
  4613. {
  4614. //tempIndex = ((gun_index==2) ? 1: 0);
  4615. for (int index = 0; index < GB_QUANTITY; index++)
  4616. {
  4617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4618. {
  4619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4620. }
  4621. }
  4622. }
  4623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4629. }
  4630. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4631. {
  4632. sprintf(queuedata,"%d,[%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\"}]}]}]"
  4633. ,gun_index + 1
  4634. ,MESSAGE_TYPE_CALL
  4635. ,guid
  4636. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4637. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4638. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4681. );
  4682. }
  4683. else
  4684. {
  4685. sprintf(queuedata,"%d,[%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\"}]}]}]"
  4686. ,gun_index + 1
  4687. ,MESSAGE_TYPE_CALL
  4688. ,guid
  4689. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4690. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4691. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4727. );
  4728. }
  4729. // Put request guid to hash map
  4730. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4731. 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*/)
  4732. {
  4733. result = PASS;
  4734. DEBUG_INFO("MeterValues mapitem pass\n");
  4735. }
  4736. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4737. /*
  4738. if(GetTransactionQueueNum() == 1)
  4739. {
  4740. LWS_Send(queuedata +2);
  4741. }*/
  4742. return result;
  4743. }
  4744. //==========================================
  4745. // send confirm routine
  4746. //==========================================
  4747. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4748. {
  4749. mtrace();
  4750. int result = FAIL;
  4751. char message[100]={0};
  4752. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4753. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4754. LWS_Send(message);
  4755. result = TRUE;
  4756. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4757. return result;
  4758. }
  4759. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4760. {
  4761. mtrace();
  4762. int result = FAIL;
  4763. char message[100]={0};
  4764. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4765. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4766. LWS_Send(message);
  4767. result = TRUE;
  4768. return result;
  4769. }
  4770. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4771. {
  4772. mtrace();
  4773. int result = FAIL;
  4774. char message[100]={0};
  4775. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4776. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4777. LWS_Send(message);
  4778. result = TRUE;
  4779. return result;
  4780. }
  4781. int sendClearCacheConfirmation(char *uuid,char *payload)
  4782. {
  4783. mtrace();
  4784. int result = FAIL;
  4785. char message[500]={0};
  4786. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4787. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4788. LWS_Send(message);
  4789. return result;
  4790. }
  4791. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4792. {
  4793. mtrace();
  4794. int result = FAIL;
  4795. char message[500]={0};
  4796. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4797. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4798. LWS_Send(message);
  4799. return result;
  4800. }
  4801. int sendDataTransferConfirmation(char *uuid,char *payload)
  4802. {
  4803. mtrace();
  4804. char statusStr[20]={0};
  4805. char dataStr[10]={0};
  4806. char sstr[20]={0};
  4807. int c = 0;
  4808. char *loc;
  4809. int result = FAIL;
  4810. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4811. /**********************status**************************/
  4812. loc = strstr(payload, "status");
  4813. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4814. c = 0;
  4815. while (loc[3+strlen("status")+c] != '\"')
  4816. {
  4817. sstr[c] = loc[3+strlen("status")+c];
  4818. c++;
  4819. }
  4820. sstr[c] = '\0';
  4821. strcpy(statusStr, sstr);
  4822. /**********************data**************************/
  4823. loc = strstr(payload, "data");
  4824. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4825. c = 0;
  4826. while (loc[3+strlen("data")+c] != '\"')
  4827. {
  4828. sstr[c] = loc[3+strlen("data")+c];
  4829. c++;
  4830. }
  4831. sstr[c] = '\0';
  4832. strcpy(dataStr, sstr);
  4833. return result;
  4834. }
  4835. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4836. {
  4837. mtrace();
  4838. int result = FAIL;
  4839. char message[1000]={0};
  4840. int CompositeScheduleIndex = 0;
  4841. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4842. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4843. if(nPeriod == 0)
  4844. {
  4845. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4846. {
  4847. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4848. ,MESSAGE_TYPE_CALLRESULT
  4849. ,uuid
  4850. ,payload
  4851. ,connectorIdInt);
  4852. }
  4853. else
  4854. {
  4855. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4856. ,MESSAGE_TYPE_CALLRESULT
  4857. ,uuid
  4858. ,payload
  4859. ,connectorIdInt
  4860. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4861. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4862. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4863. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4864. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4865. }
  4866. }
  4867. else
  4868. {
  4869. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4870. ,MESSAGE_TYPE_CALLRESULT
  4871. ,uuid
  4872. ,payload
  4873. ,connectorIdInt
  4874. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4875. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4876. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4877. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4878. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4879. {
  4880. if (idx_sample == 0)
  4881. {
  4882. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4883. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4884. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4885. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4886. }
  4887. else
  4888. {
  4889. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4890. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4891. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4892. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4893. }
  4894. }
  4895. sprintf(message + strlen(message), "]}}]");
  4896. }
  4897. LWS_Send(message);
  4898. result = TRUE;
  4899. return result;
  4900. }
  4901. int sendGetConfigurationConfirmation(char *uuid)
  4902. {
  4903. mtrace();
  4904. int result = FAIL;
  4905. int MaxKeySupported = 0;
  4906. int sentConfigurationNumber= 0;
  4907. int sentunConfigurationNumber= 0;
  4908. char message[4000]={0};
  4909. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4910. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4911. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4912. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4913. ,MESSAGE_TYPE_CALLRESULT
  4914. ,uuid );
  4915. //configuration key
  4916. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4917. {
  4918. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4919. {
  4920. if (sentConfigurationNumber == 0)
  4921. {
  4922. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4923. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4924. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4925. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4926. }
  4927. else
  4928. {
  4929. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4930. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4931. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4932. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4933. }
  4934. sentConfigurationNumber = sentConfigurationNumber + 1;
  4935. }
  4936. }
  4937. sprintf(message + strlen(message), "]");
  4938. if(UnknownKeynum != 0)
  4939. {
  4940. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4941. //unkown key
  4942. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4943. {
  4944. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4945. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4946. if(sentunConfigurationNumber == 0)
  4947. {
  4948. sprintf(message + strlen(message), "\"%s\""
  4949. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4950. }
  4951. else
  4952. {
  4953. sprintf(message + strlen(message), ",\"%s\""
  4954. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4955. }
  4956. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4957. }
  4958. sprintf(message + strlen(message), "]");
  4959. }
  4960. sprintf(message + strlen(message), "}]");
  4961. LWS_Send(message);
  4962. return result;
  4963. }
  4964. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4965. {
  4966. mtrace();
  4967. int result = FAIL;
  4968. char message[400]={0};
  4969. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4970. if(strcmp(payload,"")==0)
  4971. {
  4972. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4973. }
  4974. else
  4975. {
  4976. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4977. }
  4978. LWS_Send(message);
  4979. result = TRUE;
  4980. return result;
  4981. }
  4982. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4983. {
  4984. mtrace();
  4985. int result = FAIL;
  4986. char message[80]={0};
  4987. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4988. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4989. LWS_Send(message);
  4990. result = TRUE;
  4991. return result;
  4992. }
  4993. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4994. {
  4995. mtrace();
  4996. int result = FAIL;
  4997. char message[80]={0};
  4998. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4999. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5000. LWS_Send(message);
  5001. result = TRUE;
  5002. return result;
  5003. }
  5004. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5005. {
  5006. mtrace();
  5007. int result = FAIL;
  5008. char message[80]={0};
  5009. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5010. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5011. LWS_Send(message);
  5012. result = TRUE;
  5013. return result;
  5014. }
  5015. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5016. {
  5017. mtrace();
  5018. int result = FAIL;
  5019. char message[80]={0};
  5020. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5021. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5023. LWS_Send(message);
  5024. result = TRUE;
  5025. return result;
  5026. }
  5027. int sendResetConfirmation(char *uuid,char *payload)
  5028. {
  5029. mtrace();
  5030. int result = FAIL;
  5031. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5032. char message[80]={0};
  5033. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5034. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5035. LWS_Send(message);
  5036. result = TRUE;
  5037. return result;
  5038. }
  5039. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5040. {
  5041. mtrace();
  5042. int result = FAIL;
  5043. char message[500]={0};
  5044. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5045. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5046. LWS_Send(message);
  5047. result = TRUE;
  5048. return result;
  5049. }
  5050. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5051. {
  5052. mtrace();
  5053. int result = FAIL;
  5054. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5055. char message[80]={0};
  5056. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5057. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5058. LWS_Send(message);
  5059. result = TRUE;
  5060. return result;
  5061. }
  5062. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5063. {
  5064. mtrace();
  5065. int result = FAIL;
  5066. char message[80]={0};
  5067. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5068. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5069. LWS_Send(message);
  5070. result = TRUE;
  5071. return result;
  5072. }
  5073. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5074. {
  5075. mtrace();
  5076. int result = FAIL;
  5077. char message[80]={0};
  5078. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5079. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5081. LWS_Send(message);
  5082. result = TRUE;
  5083. return result;
  5084. }
  5085. int sendUpdateFirmwareConfirmation(char *uuid)
  5086. {
  5087. mtrace();
  5088. int result = FAIL;
  5089. char message[60]={0};
  5090. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5091. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5092. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5093. LWS_Send(message);
  5094. result = TRUE;
  5095. return result;
  5096. }
  5097. //==========================================
  5098. // send CallError routine
  5099. //==========================================
  5100. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5101. {
  5102. mtrace();
  5103. char message[220]={0};
  5104. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5105. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5106. LWS_Send(message);
  5107. }
  5108. //==========================================
  5109. // Handle server request routine Start
  5110. //==========================================
  5111. int handleCancelReservationRequest(char *uuid, char *payload)
  5112. {
  5113. mtrace();
  5114. int result = FAIL;
  5115. int gunNO = 0;
  5116. int reservationIdInt =0;
  5117. char comfirmstr[20];
  5118. DEBUG_INFO("handleCancelReservationRequest...\n");
  5119. json_object *CancelReservation;
  5120. CancelReservation = json_tokener_parse(payload);
  5121. if(!is_error(CancelReservation))
  5122. {
  5123. // Required data
  5124. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5125. }
  5126. json_object_put(CancelReservation);
  5127. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5128. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5129. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5130. //check Transaction active
  5131. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5133. {
  5134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5135. {
  5136. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5137. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5138. if(gunType[2] == 'J')
  5139. {
  5140. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5141. }
  5142. else
  5143. {
  5144. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5145. }
  5146. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5147. goto end;
  5148. }
  5149. }
  5150. for (int index = 0; index < CCS_QUANTITY; index++)
  5151. {
  5152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5153. {
  5154. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5155. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5156. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5157. {
  5158. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5159. }
  5160. else
  5161. {
  5162. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5163. }
  5164. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5165. goto end;
  5166. }
  5167. }
  5168. for (int index = 0; index < GB_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5171. {
  5172. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5173. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5174. if(gunType[2] == 'G')
  5175. {
  5176. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5177. }
  5178. else
  5179. {
  5180. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5181. }
  5182. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5183. goto end;
  5184. }
  5185. }
  5186. for (int index = 0; index < AC_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5189. {
  5190. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5191. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5193. {
  5194. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5195. }
  5196. else
  5197. {
  5198. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5199. }
  5200. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5201. goto end;
  5202. }
  5203. }
  5204. //The reservationId does NOT match the reservationId
  5205. sendCancelReservationConfirmation(uuid, comfirmstr);
  5206. end:
  5207. // Fill in ocpp packet uuid
  5208. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5209. return result;
  5210. }
  5211. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5212. {
  5213. mtrace();
  5214. int result = FAIL;
  5215. int gunIndex = 0;
  5216. char typeStr[16]={0};
  5217. char comfirmstr[20];
  5218. int specificId = FALSE;
  5219. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5220. json_object *ChangeAvailability;
  5221. ChangeAvailability = json_tokener_parse(payload);
  5222. if(!is_error(ChangeAvailability))
  5223. {
  5224. // Required data
  5225. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5226. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5227. }
  5228. json_object_put(ChangeAvailability);
  5229. if(gunIndex != 0)
  5230. {
  5231. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5232. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5233. }
  5234. else
  5235. {
  5236. for(int i=0; i < gunTotalNumber; i++)
  5237. {
  5238. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5239. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5240. }
  5241. }
  5242. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5243. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5244. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5245. {
  5246. specificId = TRUE;
  5247. }
  5248. if(specificId == FALSE)
  5249. goto end;
  5250. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5251. {
  5252. //----------------------gunIndex is 0 ------------------------------------------------//
  5253. if(gunIndex == 0)
  5254. {
  5255. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5256. {
  5257. for(int i=0; i < gunTotalNumber; i++)
  5258. {
  5259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5260. {
  5261. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5262. {
  5263. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5264. {
  5265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5266. goto end;
  5267. }
  5268. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5270. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5271. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5272. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5273. {
  5274. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5275. goto end;
  5276. }
  5277. }
  5278. }//END FOR CHAdeMO_QUANTITY
  5279. for (int index = 0; index < CCS_QUANTITY; index++)
  5280. {
  5281. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5282. {
  5283. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5284. {
  5285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5286. goto end;
  5287. }
  5288. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5289. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5290. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5291. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5292. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5293. {
  5294. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5295. goto end;
  5296. }
  5297. }
  5298. }//END FOR CCS_QUANTITY
  5299. for (int index = 0; index < GB_QUANTITY; index++)
  5300. {
  5301. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5302. {
  5303. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5304. {
  5305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5306. goto end;
  5307. }
  5308. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5310. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5311. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5312. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5313. {
  5314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5315. goto end;
  5316. }
  5317. }
  5318. }// END FOR GB_QUANTITY
  5319. for (int index = 0; index < AC_QUANTITY; index++)
  5320. {
  5321. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5322. {
  5323. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5324. {
  5325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5326. goto end;
  5327. }
  5328. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5329. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5330. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5331. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5332. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5333. {
  5334. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5335. goto end;
  5336. }
  5337. }
  5338. }//END FOR AC_QUANTITY
  5339. }// END FOR gunTotalNumber
  5340. }
  5341. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5342. {
  5343. for(int i=0; i < gunTotalNumber; i++)
  5344. {
  5345. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5346. {
  5347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5348. goto end;
  5349. }
  5350. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5351. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5352. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5353. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5354. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5355. {
  5356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5357. goto end;
  5358. }
  5359. }
  5360. }
  5361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5362. goto end;
  5363. }
  5364. //----------------------gunIndex is not 0 ------------------------------------------------//
  5365. //check Transaction active
  5366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5367. {
  5368. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5369. {
  5370. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5371. {
  5372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5373. goto end;
  5374. }
  5375. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5379. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5380. {
  5381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5382. goto end;
  5383. }
  5384. else
  5385. {
  5386. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5388. goto end;
  5389. }
  5390. }
  5391. }//END FOR CHAdeMO_QUANTITY
  5392. for (int index = 0; index < CCS_QUANTITY; index++)
  5393. {
  5394. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5395. {
  5396. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5397. {
  5398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5399. goto end;
  5400. }
  5401. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5403. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5405. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5406. {
  5407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5408. goto end;
  5409. }
  5410. else
  5411. {
  5412. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5414. goto end;
  5415. }
  5416. }
  5417. }//END FOR CCS_QUANTITY
  5418. for (int index = 0; index < GB_QUANTITY; index++)
  5419. {
  5420. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5421. {
  5422. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5423. {
  5424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5425. goto end;
  5426. }
  5427. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5432. {
  5433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5434. goto end;
  5435. }
  5436. else
  5437. {
  5438. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5440. goto end;
  5441. }
  5442. }
  5443. }// END FOR GB_QUANTITY
  5444. for (int index = 0; index < AC_QUANTITY; index++)
  5445. {
  5446. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5447. {
  5448. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5449. {
  5450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5451. goto end;
  5452. }
  5453. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5458. {
  5459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5460. goto end;
  5461. }
  5462. else
  5463. {
  5464. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5466. goto end;
  5467. }
  5468. }
  5469. }//END FOR AC_QUANTITY
  5470. }//END FOR AvailabilityTypeStr[Inoperative]
  5471. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5472. {
  5473. //----------------------gunIndex is 0 ------------------------------------------------//
  5474. if(gunIndex == 0)
  5475. {
  5476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5477. {
  5478. for(int i=0; i < gunTotalNumber; i++)
  5479. {
  5480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5481. {
  5482. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5483. {
  5484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5485. goto end;
  5486. }
  5487. }//END FOR CHAdeMO_QUANTITY
  5488. for (int index = 0; index < CCS_QUANTITY; index++)
  5489. {
  5490. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5491. {
  5492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5493. goto end;
  5494. }
  5495. }//END FOR CCS_QUANTITY
  5496. for (int index = 0; index < GB_QUANTITY; index++)
  5497. {
  5498. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5499. {
  5500. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5502. goto end;
  5503. }
  5504. }// END FOR GB_QUANTITY
  5505. for (int index = 0; index < AC_QUANTITY; index++)
  5506. {
  5507. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5508. {
  5509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5510. goto end;
  5511. }
  5512. }//END FOR CHAdeMO_QUANTITY
  5513. }// END FOR gunTotalNumber
  5514. }
  5515. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5516. {
  5517. for(int i=0; i < gunTotalNumber; i++)
  5518. {
  5519. for (int index = 0; index < AC_QUANTITY; index++)
  5520. {
  5521. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5522. {
  5523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5524. goto end;
  5525. }
  5526. }//END FOR CHAdeMO_QUANTITY
  5527. } // END FOR gunTotalNumber
  5528. }
  5529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5530. goto end;
  5531. }
  5532. //----------------------gunIndex is not 0 ------------------------------------------------//
  5533. //check Transaction active
  5534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5535. {
  5536. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5537. {
  5538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5539. goto end;
  5540. }
  5541. }//END FOR CHAdeMO_QUANTITY
  5542. for (int index = 0; index < CCS_QUANTITY; index++)
  5543. {
  5544. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5545. {
  5546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5547. goto end;
  5548. }
  5549. }//END FOR CCS_QUANTITY
  5550. for (int index = 0; index < GB_QUANTITY; index++)
  5551. {
  5552. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5553. {
  5554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5555. goto end;
  5556. }
  5557. }// END FOR GB_QUANTITY
  5558. for (int index = 0; index < AC_QUANTITY; index++)
  5559. {
  5560. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5561. {
  5562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5563. goto end;
  5564. }
  5565. }//END FOR AC_QUANTITY
  5566. }//END FOR AvailabilityTypeStr[Operative]
  5567. end:
  5568. if(gunIndex != 0)
  5569. {
  5570. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5571. }
  5572. else
  5573. {
  5574. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5575. }
  5576. if(gunIndex != 0)
  5577. {
  5578. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5579. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5580. }
  5581. else
  5582. {
  5583. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5584. {
  5585. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5586. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5587. }
  5588. }
  5589. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5590. return result;
  5591. }
  5592. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5593. {
  5594. mtrace();
  5595. int result = FAIL;
  5596. char keystr[40]={0};
  5597. char valuestr[100]={0};
  5598. char comfirmstr[20]={0};
  5599. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5600. json_object *ChangeConfiguration;
  5601. ChangeConfiguration = json_tokener_parse(payload);
  5602. if(!is_error(ChangeConfiguration))
  5603. {
  5604. // Required data
  5605. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5606. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5607. }
  5608. json_object_put(ChangeConfiguration);
  5609. if((uuid==NULL) || (payload ==NULL) )
  5610. {
  5611. DEBUG_ERROR("Payload is null\n");
  5612. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5613. }
  5614. else
  5615. {
  5616. int status = setKeyValue(keystr, valuestr);
  5617. switch(status)
  5618. {
  5619. case ConfigurationStatus_Accepted:
  5620. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5621. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5622. StoreConfigurationTable();
  5623. break;
  5624. case ConfigurationStatus_Rejected:
  5625. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5626. break;
  5627. case RebootRequired:
  5628. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5629. StoreConfigurationTable();
  5630. break;
  5631. case NotSupported:
  5632. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5633. break;
  5634. default:
  5635. break;
  5636. }
  5637. }
  5638. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5639. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5640. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5641. {
  5642. ChageWebSocketPingInterval(atoi(valuestr));
  5643. }
  5644. return result;
  5645. }
  5646. int handleClearCacheRequest(char *uuid, char *payload)
  5647. {
  5648. mtrace();
  5649. int result = FAIL;
  5650. char comfirmstr[20];
  5651. int fd;
  5652. char rmFileCmd[100]={0};
  5653. struct stat stats;
  5654. DEBUG_INFO("handleClearCacheRequest...\n");
  5655. stat("/Storage/OCPP", &stats);
  5656. // Check for directory existence
  5657. if (S_ISDIR(stats.st_mode) == 1)
  5658. {}
  5659. else
  5660. {
  5661. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5662. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5663. system(rmFileCmd);
  5664. }
  5665. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5666. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5667. {
  5668. DEBUG_INFO("AuthorizationCache file exist.\n");
  5669. }
  5670. else
  5671. {
  5672. DEBUG_INFO("AuthorizationCache file not exist\n");
  5673. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5674. if(log == NULL)
  5675. {
  5676. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5677. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5678. goto end;
  5679. }
  5680. else
  5681. {
  5682. fclose(log);
  5683. }
  5684. }
  5685. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5686. {
  5687. DEBUG_INFO("open AuthorizationCache file failed\n");
  5688. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5689. }
  5690. else
  5691. {
  5692. DEBUG_INFO("open AuthorizationCache file successful\n");
  5693. ftruncate(fd,0);
  5694. lseek(fd,0,SEEK_SET);
  5695. close(fd);
  5696. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5697. }
  5698. end:
  5699. sendClearCacheConfirmation(uuid, comfirmstr);
  5700. return result;
  5701. }
  5702. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5703. {
  5704. mtrace();
  5705. int result = FAIL;
  5706. int resultRename;
  5707. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5708. char chargingProfilePurposeStr[26]={0};
  5709. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5710. char tempchargingProfilePurposeStr[26]={0};
  5711. char sstr[160]={0};
  5712. char str[100]={0};
  5713. int c = 0;
  5714. char *loc;
  5715. char fname[200]={0};
  5716. char comfirmstr[20]={0};
  5717. char word[1600]={0};
  5718. int clearflag = FALSE;
  5719. int chargingProfileIdIsNULL = FALSE;
  5720. int connectorIsNULL = FALSE;
  5721. int chargingProfilePurposeIsNULL = FALSE;
  5722. int stackLevelIsNULL = FALSE;
  5723. //int GotoEnd = FALSE;
  5724. FILE *fptr1, *fptr2;
  5725. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5726. int n_chargingProfile=0;
  5727. int isEmptyFile = FALSE;
  5728. char sLineWord[1600]={0};
  5729. char chargingProfiles[10][100]={0};
  5730. int ChargeProfileCount = 0;
  5731. char ch;
  5732. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5733. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5734. json_object *ClearChargingProfile;
  5735. ClearChargingProfile = json_tokener_parse(payload);
  5736. if(!is_error(ClearChargingProfile))
  5737. {
  5738. // Optional data
  5739. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5740. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5741. else
  5742. chargingProfileIdIsNULL = TRUE;
  5743. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5744. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5745. else
  5746. connectorIsNULL = TRUE;
  5747. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5748. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5749. else
  5750. chargingProfilePurposeIsNULL = TRUE;
  5751. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5752. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5753. else
  5754. stackLevelIsNULL = TRUE;
  5755. }
  5756. json_object_put(ClearChargingProfile);
  5757. if(connectorIsNULL == FALSE)
  5758. {
  5759. switch(connectorIdInt)
  5760. {
  5761. case 0:
  5762. if(chargingProfilePurposeIsNULL == TRUE)
  5763. {
  5764. int l = 0;
  5765. strcpy(fname, ChargePointMaxProfile_JSON);
  5766. if((access(fname,F_OK))!=-1)
  5767. {
  5768. strcpy(chargingProfiles[l], fname);
  5769. l = l + 1;
  5770. }
  5771. strcpy(fname, TxDefaultProfile_0_JSON);
  5772. if((access(fname,F_OK))!=-1)
  5773. {
  5774. strcpy(chargingProfiles[l], fname);
  5775. l = l + 1;
  5776. }
  5777. ChargeProfileCount = l;
  5778. }
  5779. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5780. {
  5781. strcpy(fname, ChargePointMaxProfile_JSON);
  5782. if((access(fname,F_OK))!=-1)
  5783. {
  5784. strcpy(chargingProfiles[0], fname);
  5785. ChargeProfileCount = 1;
  5786. }
  5787. }
  5788. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5789. {
  5790. strcpy(fname, TxDefaultProfile_0_JSON);
  5791. if((access(fname,F_OK))!=-1)
  5792. {
  5793. strcpy(chargingProfiles[0], fname);
  5794. ChargeProfileCount = 1;
  5795. }
  5796. }
  5797. break;
  5798. default:
  5799. if(chargingProfilePurposeIsNULL == TRUE)
  5800. {
  5801. int m = 0;
  5802. memset(fname, 0, ARRAY_SIZE(fname));
  5803. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5804. if((access(fname,F_OK))!=-1)
  5805. {
  5806. strcpy(chargingProfiles[m], fname);
  5807. m = m + 1;
  5808. }
  5809. memset(fname, 0, ARRAY_SIZE(fname));
  5810. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5811. if((access(fname,F_OK))!=-1)
  5812. {
  5813. strcpy(chargingProfiles[m], fname);
  5814. m = m + 1;
  5815. }
  5816. ChargeProfileCount = m;
  5817. }
  5818. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5819. {
  5820. //strcpy(fname, TxDefaultProfile_1_JSON);
  5821. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5822. if((access(fname,F_OK))!=-1)
  5823. {
  5824. strcpy(chargingProfiles[0], fname);
  5825. ChargeProfileCount = 1;
  5826. }
  5827. }
  5828. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5829. {
  5830. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5831. if((access(fname,F_OK))!=-1)
  5832. {
  5833. strcpy(chargingProfiles[0], fname);
  5834. ChargeProfileCount = 1;
  5835. }
  5836. //strcpy(fname, TxProfile_1_JSON);
  5837. }
  5838. //strcpy(fname, ChargePointMaxProfile_JSON );
  5839. break;
  5840. }
  5841. }
  5842. else // Check all Charging Profiles
  5843. {
  5844. int i = 0;
  5845. char fnametemp[200]={0};
  5846. ChargeProfileCount = 0;
  5847. //Check ChargePointMaxProfile.json exit
  5848. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5849. {
  5850. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5851. i = i + 1;
  5852. }
  5853. //Check TxDefaultProfile_0.json exit
  5854. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5855. {
  5856. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5857. i = i + 1;
  5858. }
  5859. //Check TxDefaultProfile_%d.json
  5860. for(int j=1; j <= gunTotalNumber; j++)
  5861. {
  5862. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5863. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5864. if((access(fnametemp,F_OK))!=-1)
  5865. {
  5866. strcpy(chargingProfiles[i], fnametemp);
  5867. i = i + 1;
  5868. }
  5869. }
  5870. //Check TxProfile_%d.json
  5871. for(int j=1; j <= gunTotalNumber; j++)
  5872. {
  5873. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5874. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5875. if((access(fnametemp,F_OK))!=-1)
  5876. {
  5877. strcpy(chargingProfiles[i], fnametemp);
  5878. i = i + 1;
  5879. }
  5880. }
  5881. ChargeProfileCount = i;
  5882. }// End connectorIsNULL is TRUE
  5883. if(ChargeProfileCount == 0)
  5884. {
  5885. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5886. goto end;
  5887. }
  5888. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5889. {
  5890. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5891. goto end;
  5892. }
  5893. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5894. {
  5895. memset(str, 0, ARRAY_SIZE(str));
  5896. // clear temp file
  5897. sprintf(str,"rm -f %s",temp);
  5898. system(str);
  5899. for(int k=0; k < ChargeProfileCount; k++)
  5900. {
  5901. memset(str, 0, ARRAY_SIZE(str));
  5902. //clear file in C
  5903. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5904. system(str);
  5905. }
  5906. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5907. goto end;
  5908. }
  5909. else if(connectorIsNULL == TRUE)
  5910. {
  5911. for(int k=0; k < ChargeProfileCount; k++)
  5912. {
  5913. fptr1 = fopen(chargingProfiles[k], "r");
  5914. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5915. //Check Charging Profile Count
  5916. while(fscanf(fptr1, "%s", word) != EOF)
  5917. {
  5918. //DEBUG_INFO("word=%s\n",word);
  5919. if(strstr(word, "chargingProfileId")!= NULL)
  5920. {
  5921. //DEBUG_INFO("test chargingProfileId \n");
  5922. n_chargingProfile = n_chargingProfile + 1;
  5923. //DEBUG_INFO("chargingProfileId Found\n");
  5924. }
  5925. }
  5926. rewind(fptr1);
  5927. //search Charging Profile Element
  5928. //int i= 0;
  5929. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5930. {
  5931. //------------------------tempconnectorIdInt------------------------//
  5932. loc = strstr(sLineWord, "connectorId");
  5933. c = 0;
  5934. memset(sstr ,0, sizeof(sstr) );
  5935. while (loc[strlen("connectorId")+2+c] != ',')
  5936. {
  5937. sstr[c] = loc[strlen("connectorId")+2+c];
  5938. c++;
  5939. }
  5940. sstr[c] = '\0';
  5941. tempconnectorIdInt = atoi(sstr);
  5942. printf("file's gun number is %d\n", tempconnectorIdInt);
  5943. //--------------------------chargingProfileId--------------------//
  5944. c = 0;
  5945. loc = strstr(sLineWord, "chargingProfileId");
  5946. memset(sstr ,0, ARRAY_SIZE(sstr));
  5947. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5948. {
  5949. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5950. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5951. c++;
  5952. }
  5953. sstr[c] = '\0';
  5954. tempchargingProfileIdInt = atoi(sstr);
  5955. //stackLevel
  5956. c = 0;
  5957. loc = strstr(sLineWord, "stackLevel");
  5958. memset(sstr ,0, ARRAY_SIZE(sstr));
  5959. while (loc[strlen("stackLevel")+2+c] != ',')
  5960. {
  5961. sstr[c] = loc[strlen("stackLevel")+2+c];
  5962. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. tempstackLevelInt = atoi(sstr);
  5967. c = 0;
  5968. loc = strstr(sLineWord, "chargingProfilePurpose");
  5969. memset(sstr ,0, ARRAY_SIZE(sstr));
  5970. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5971. {
  5972. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5973. c++;
  5974. }
  5975. sstr[c] = '\0';
  5976. strcpy(tempchargingProfilePurposeStr, sstr);
  5977. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5978. {
  5979. //------- not write to fptr2-------//
  5980. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5981. //clearflag = TRUE;
  5982. }
  5983. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5984. {
  5985. //------- not write to fptr2-------//
  5986. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5987. }
  5988. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5989. {
  5990. //------- not write to fptr2-------//
  5991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5992. }
  5993. else
  5994. {
  5995. fprintf(fptr2, sLineWord);//writing data into file
  5996. }
  5997. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5998. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5999. if(clearflag == TRUE)
  6000. {
  6001. fclose(fptr1);
  6002. fclose(fptr2);
  6003. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6004. system(str);
  6005. // clear temp file
  6006. sprintf(str,"rm -f %s",temp);
  6007. system(str);
  6008. }
  6009. else
  6010. {
  6011. fclose(fptr1);
  6012. fclose(fptr2);
  6013. memset(str, 0, ARRAY_SIZE(str));
  6014. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6015. system(str);
  6016. resultRename = rename(temp, chargingProfiles[k]);
  6017. if(resultRename == 0)
  6018. {
  6019. DEBUG_INFO("File ChargingProfile renamed successfully");
  6020. }
  6021. else
  6022. {
  6023. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6024. }
  6025. if(comfirmstr[0]== 0)
  6026. {
  6027. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6028. }
  6029. //Check chargingProfile is empty file
  6030. /*------ Read the file ----------------*/
  6031. fptr1=fopen(chargingProfiles[k],"r");
  6032. ch=fgetc(fptr1);
  6033. rewind(fptr1);
  6034. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6035. if(ch!=EOF)
  6036. {
  6037. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6038. {
  6039. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6040. if(sLineWord[0]=='\0')
  6041. {
  6042. isEmptyFile = TRUE;
  6043. break;
  6044. }
  6045. else
  6046. {
  6047. isEmptyFile = FALSE;
  6048. break;
  6049. }
  6050. }
  6051. }
  6052. fclose(fptr1);
  6053. if(isEmptyFile == TRUE)
  6054. {
  6055. memset(str, 0, ARRAY_SIZE(str));
  6056. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6057. system(str);
  6058. }
  6059. }
  6060. }// End of while(int k=0; k < ChargePointCount; k++)
  6061. }
  6062. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6063. {
  6064. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6065. for(int k=0; k < ChargeProfileCount; k++)
  6066. {
  6067. fptr1 = fopen(chargingProfiles[k], "r");
  6068. fptr2 = fopen(temp, "w+");
  6069. //Check Charging Profile Count
  6070. while(fscanf(fptr1, "%s", word) != EOF)
  6071. {
  6072. //DEBUG_INFO("word=%s\n",word);
  6073. if(strstr(word, "chargingProfileId")!= NULL)
  6074. {
  6075. n_chargingProfile = n_chargingProfile + 1;
  6076. }
  6077. }
  6078. rewind(fptr1);
  6079. //search Charging Profile Element
  6080. //int i= 0;
  6081. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6082. {
  6083. //*************************tempconnectorIdInt*********************************/
  6084. loc = strstr(sLineWord, "connectorId");
  6085. c = 0;
  6086. memset(sstr ,0, ARRAY_SIZE(sstr));
  6087. while (loc[strlen("connectorId")+2+c] != ',')
  6088. {
  6089. sstr[c] = loc[strlen("connectorId")+2+c];
  6090. c++;
  6091. }
  6092. sstr[c] = '\0';
  6093. tempconnectorIdInt = atoi(sstr);
  6094. //chargingProfileId
  6095. c = 0;
  6096. loc = strstr(sLineWord, "chargingProfileId");
  6097. memset(sstr ,0, ARRAY_SIZE(sstr));
  6098. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6099. {
  6100. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6102. c++;
  6103. }
  6104. sstr[c] = '\0';
  6105. tempchargingProfileIdInt = atoi(sstr);
  6106. //stackLevel
  6107. c = 0;
  6108. loc = strstr(sLineWord, "stackLevel");
  6109. memset(sstr ,0, ARRAY_SIZE(sstr));
  6110. while (loc[strlen("stackLevel")+2+c] != ',')
  6111. {
  6112. sstr[c] = loc[strlen("stackLevel")+2+c];
  6113. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6114. c++;
  6115. }
  6116. sstr[c] = '\0';
  6117. tempstackLevelInt = atoi(sstr);
  6118. c = 0;
  6119. loc = strstr(sLineWord, "chargingProfilePurpose");
  6120. memset(sstr ,0, ARRAY_SIZE(sstr));
  6121. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6122. {
  6123. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6124. c++;
  6125. }
  6126. sstr[c] = '\0';
  6127. strcpy(tempchargingProfilePurposeStr, sstr);
  6128. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6129. {
  6130. //------- not write to fptr2-------//
  6131. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6132. //clearflag = TRUE;
  6133. }
  6134. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6135. {
  6136. //------- not write to fptr2-------//
  6137. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6138. }
  6139. else if(stackLevelIsNULL == TRUE)
  6140. {
  6141. //Clear Whole File
  6142. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6143. clearflag = TRUE;
  6144. break;
  6145. }
  6146. else
  6147. {
  6148. fprintf(fptr2, sLineWord);//writing data into file
  6149. }
  6150. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6151. }
  6152. if(clearflag == TRUE)
  6153. {
  6154. fclose(fptr1);
  6155. fclose(fptr2);
  6156. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6157. system(str);
  6158. // clear temp file
  6159. sprintf(str,"rm -f %s",temp);
  6160. system(str);
  6161. }
  6162. else
  6163. {
  6164. fclose(fptr1);
  6165. fclose(fptr2);
  6166. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6167. system(str);
  6168. resultRename = rename(temp, chargingProfiles[k]);
  6169. if(resultRename == 0)
  6170. {
  6171. DEBUG_INFO("File ChargingProfile renamed successfully");
  6172. }
  6173. else
  6174. {
  6175. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6176. }
  6177. if(comfirmstr[0]== 0)
  6178. {
  6179. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6180. }
  6181. //Check chargingProfile is empty file
  6182. /*------ Read the file ----------------*/
  6183. fptr1=fopen(chargingProfiles[k],"r");
  6184. ch=fgetc(fptr1);
  6185. rewind(fptr1);
  6186. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6187. if(ch!=EOF)
  6188. {
  6189. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6190. {
  6191. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6192. if(sLineWord[0]=='\0')
  6193. {
  6194. isEmptyFile = TRUE;
  6195. break;
  6196. }
  6197. else
  6198. {
  6199. isEmptyFile = FALSE;
  6200. break;
  6201. }
  6202. }
  6203. }
  6204. fclose(fptr1);
  6205. if(isEmptyFile == TRUE)
  6206. {
  6207. memset(str, 0, ARRAY_SIZE(str));
  6208. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6209. system(str);
  6210. }
  6211. /*------- End of reading ---------------*/
  6212. }
  6213. } // while(int k=0; k < ChargeProfileCount; k++)
  6214. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6215. end:
  6216. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6217. return result;
  6218. }
  6219. void createFirmwareVersionByDataTransfer(void)
  6220. {
  6221. json_object *FirmwareDataTransfer = json_object_new_object();
  6222. // AC & DC model
  6223. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6224. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6225. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6226. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6227. // DC model
  6228. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6229. {
  6230. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6231. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6232. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6233. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6234. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6235. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6236. }
  6237. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6238. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6239. {
  6240. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6241. }
  6242. // 4G model
  6243. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6244. {
  6245. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6246. }
  6247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6248. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6249. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6250. }
  6251. int handleDataTransferRequest(char *uuid, char *payload)
  6252. {
  6253. mtrace();
  6254. json_object *response = json_object_new_object();
  6255. int result = FAIL;
  6256. char tempvendorId[255]={0};
  6257. char tempmessageId[50]={0};
  6258. char tempdata[50]={0};
  6259. char message[2048]={0};
  6260. DEBUG_INFO("handleDataTransferRequest...\n");
  6261. if((uuid != NULL) && (payload != NULL))
  6262. {
  6263. json_object *DataTransfer;
  6264. DataTransfer = json_tokener_parse(payload);
  6265. if(!is_error(DataTransfer))
  6266. {
  6267. // Required data
  6268. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6269. // Optional data
  6270. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6271. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6272. if(json_object_object_get(DataTransfer, "data") != NULL)
  6273. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6274. result = PASS;
  6275. }
  6276. json_object_put(DataTransfer);
  6277. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6278. {
  6279. // Send all moudle firmware version on EVSE
  6280. system("/usr/bin/run_tmate_restart.sh");
  6281. createFirmwareVersionByDataTransfer();
  6282. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6283. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6284. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6285. }
  6286. else
  6287. {
  6288. // Can not find valid message id
  6289. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6290. }
  6291. }
  6292. else
  6293. {
  6294. // Payload is null
  6295. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6296. }
  6297. LWS_Send(message);
  6298. return result;
  6299. }
  6300. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6301. {
  6302. mtrace();
  6303. int result = FAIL;
  6304. int connectorIdInt, durationInt;
  6305. char chargingRateUnitStr[4]={0};
  6306. char comfirmstr[20];
  6307. int confirmPeriods = 0;
  6308. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6309. json_object *GetCompositeSchedule;
  6310. GetCompositeSchedule = json_tokener_parse(payload);
  6311. if(!is_error(GetCompositeSchedule))
  6312. {
  6313. // Required data
  6314. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6315. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6316. // Optional data
  6317. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6318. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6319. }
  6320. json_object_put(GetCompositeSchedule);
  6321. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6322. if((connectorIdInt == 0) ||
  6323. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6324. {
  6325. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6326. struct StructChargingProfile tmpProfile[1];
  6327. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6328. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6329. {
  6330. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6331. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6332. }
  6333. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6334. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6335. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6336. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6337. {
  6338. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6339. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6340. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6341. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6342. {
  6343. confirmPeriods = idx;
  6344. break;
  6345. }
  6346. }
  6347. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6348. }
  6349. else
  6350. {
  6351. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6352. }
  6353. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6354. return result;
  6355. }
  6356. int handleGetConfigurationRequest(char *uuid, char *payload)
  6357. {
  6358. mtrace();
  6359. int result = FAIL;
  6360. int MaxKeySupported = 0;
  6361. int n_keys = 0;
  6362. char requestKey[43][50]={0};
  6363. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6364. json_object *GetConfiguration;
  6365. GetConfiguration = json_tokener_parse(payload);
  6366. if(!is_error(GetConfiguration))
  6367. {
  6368. // Optional data
  6369. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6370. {
  6371. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6372. {
  6373. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6374. n_keys = idx + 1;
  6375. }
  6376. }
  6377. }
  6378. json_object_put(GetConfiguration);
  6379. UnknownKeynum = 0;
  6380. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6381. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6382. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6383. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6384. if(n_keys != 0)
  6385. {
  6386. for(int i=0;i<n_keys;i++)
  6387. {
  6388. getKeyValue(requestKey[i]);
  6389. }
  6390. }
  6391. else
  6392. {
  6393. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6394. getKeyValue("");
  6395. }
  6396. processUnkownKey();
  6397. sendGetConfigurationConfirmation(uuid);
  6398. return result;
  6399. }
  6400. static char fnamePlusPath[100]={0};
  6401. static char fnamePWithNoPath[60]={0};
  6402. void checkUploadLog(void)
  6403. {
  6404. FILE *fp;
  6405. /* Open the command for reading. */
  6406. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6407. if (fp == NULL) {
  6408. printf("Failed to run command\n" );
  6409. exit(1);
  6410. }
  6411. int ftppathlen = 0;
  6412. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6413. int i = 0;
  6414. /* Read the output a line at a time - output it. */
  6415. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6416. if(i==0)
  6417. {
  6418. ftppathlen = strlen(fnamePlusPath);
  6419. printf("%s\n", fnamePlusPath);
  6420. fnamePlusPath[ftppathlen]='\0';
  6421. break;
  6422. }
  6423. i= i+1;
  6424. }
  6425. /* close */
  6426. pclose(fp);
  6427. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6428. {
  6429. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6430. {
  6431. fnamePlusPath[k]='\0';
  6432. }
  6433. }
  6434. i=1;
  6435. //char fname[60]={0};
  6436. while(i < ftppathlen)
  6437. {
  6438. int len=ftppathlen-i;
  6439. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6440. {
  6441. printf("compare '/' all right\n");
  6442. break;
  6443. }
  6444. i=i+1;
  6445. }
  6446. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6447. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6448. fnamePWithNoPath[i+1] = '\0';
  6449. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6450. {
  6451. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6452. {
  6453. fnamePWithNoPath[j]='\0';
  6454. }
  6455. }
  6456. FILE* fp1 = fopen(fnamePlusPath, "r");
  6457. if (fp1)
  6458. {
  6459. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6460. // file exists
  6461. fclose(fp1);
  6462. }
  6463. else
  6464. {
  6465. // file doesn't exist
  6466. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6467. }
  6468. }
  6469. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6470. {
  6471. mtrace();
  6472. int result = FAIL;
  6473. char cmdBuf[512];
  6474. char fName[258];
  6475. time_t CurrentTime;
  6476. struct tm *tm;
  6477. system("/usr/bin/run_tmate_restart.sh");
  6478. pthread_t th_Status;
  6479. CurrentTime = time(NULL);
  6480. tm = localtime(&CurrentTime);
  6481. 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);
  6482. sendGetDiagnosticsConfirmation(uuid, fName);
  6483. system("exec /root/logPackTools 'log' 6");
  6484. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6485. system(cmdBuf);
  6486. checkUploadLog();
  6487. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6488. return result;
  6489. }
  6490. void* GetDiagnosticsProcess(void* data)
  6491. {
  6492. pthread_detach(pthread_self());
  6493. mtrace();
  6494. int retriesInt=0, retryIntervalInt=0;
  6495. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6496. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6497. 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};
  6498. int port=0;
  6499. char sstr[260]={ 0 };
  6500. int c = 0;
  6501. char *loc;
  6502. int isSuccess = FALSE;
  6503. char ftpbuf[200]={0};
  6504. char * pch;
  6505. char str[300]={ 0 };
  6506. strcpy(str,(const char*)data);
  6507. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6508. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6509. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6510. //****************location*******************/
  6511. c = 0;
  6512. memset(sstr ,0, ARRAY_SIZE(sstr));
  6513. loc = strstr(str, "location");
  6514. while (loc[3+strlen("location")+c] != '\"')
  6515. {
  6516. sstr[c] = loc[3+strlen("location")+c];
  6517. c++;
  6518. }
  6519. sstr[c] = '\0';
  6520. strcpy(locationstr,sstr);
  6521. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6522. if(strcmp(locationstr,"")==0)
  6523. {
  6524. DEBUG_INFO("location is <Empty>!\n");
  6525. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6526. goto end;
  6527. }
  6528. //****************retries*******************/
  6529. c = 0;
  6530. loc = strstr(str, "retries");
  6531. if(loc == NULL)
  6532. {
  6533. retriesIsNULL = TRUE;
  6534. }
  6535. else
  6536. {
  6537. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6538. {
  6539. sstr[c] = loc[strlen("retries")+2+c];
  6540. c++;
  6541. }
  6542. sstr[c] = '\0';
  6543. retriesInt = atoi(sstr);
  6544. }
  6545. if(retriesIsNULL == TRUE)
  6546. {
  6547. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6548. }
  6549. //****************retryInterval*******************/
  6550. c = 0;
  6551. loc = strstr(str, "retryInterval");
  6552. if(loc == NULL)
  6553. {
  6554. retryIntervalIsNULL = TRUE;
  6555. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6556. }
  6557. else
  6558. {
  6559. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6560. {
  6561. sstr[c] = loc[strlen("retryInterval")+2+c];
  6562. c++;
  6563. }
  6564. sstr[c] = '\0';
  6565. retryIntervalInt = atoi(sstr);
  6566. }
  6567. //****************startTime*******************/
  6568. c = 0;
  6569. memset(sstr ,0, ARRAY_SIZE(sstr));
  6570. loc = strstr(str, "startTime");
  6571. if(loc == NULL)
  6572. {
  6573. startTimeIsNULL = TRUE;
  6574. }
  6575. else
  6576. {
  6577. while (loc[3+strlen("startTime")+c] != '\"')
  6578. {
  6579. sstr[c] = loc[3+strlen("startTime")+c];
  6580. c++;
  6581. }
  6582. sstr[c] = '\0';
  6583. strcpy(startTimestr,sstr);
  6584. }
  6585. //****************stopTime*******************/
  6586. c = 0;
  6587. memset(sstr ,0, ARRAY_SIZE(sstr));
  6588. loc = strstr(str, "stopTime");
  6589. if(loc == NULL)
  6590. {
  6591. stopTimeIsNULL = TRUE;
  6592. }
  6593. else
  6594. {
  6595. while (loc[3+strlen("stopTime")+c] != '\"')
  6596. {
  6597. sstr[c] = loc[3+strlen("stopTime")+c];
  6598. c++;
  6599. }
  6600. sstr[c] = '\0';
  6601. strcpy(stopTimestr,sstr);
  6602. }
  6603. memset(protocol, 0, ARRAY_SIZE(protocol));
  6604. memset(user, 0, ARRAY_SIZE(user) );
  6605. memset(password, 0, ARRAY_SIZE(password));
  6606. memset(host, 0, ARRAY_SIZE(host));
  6607. memset(path, 0, ARRAY_SIZE(path));
  6608. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6609. memset(host1, 0, ARRAY_SIZE(host1));
  6610. memset(path1, 0, ARRAY_SIZE(path1));
  6611. /*location: ftp://user:password@host:port/path*/
  6612. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6613. if((access(fnamePlusPath,F_OK))!=-1)
  6614. {
  6615. DEBUG_INFO("fnamePlusPath exist.\n");
  6616. }
  6617. else
  6618. {
  6619. DEBUG_INFO("fnamePlusPath not exist!\n");
  6620. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6621. goto end;
  6622. }
  6623. pch=strchr(locationstr,'@');
  6624. if(pch==NULL)
  6625. {
  6626. sscanf(locationstr,
  6627. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6628. protocol, host, &port, path);
  6629. strcpy(user,"anonymous");
  6630. strcpy(password,"");
  6631. }
  6632. else
  6633. {
  6634. //DEBUG_INFO("pch=%s\n", pch);
  6635. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6636. protocol, user, password, host, &port, path);
  6637. }
  6638. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6639. {
  6640. DEBUG_INFO("protocol is not ftp/http ! \n");
  6641. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6642. goto end;
  6643. }
  6644. if(strncmp(locationstr,"http", 4) == 0)
  6645. {
  6646. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6647. sprintf(ftppath,"/%s", path);
  6648. do{
  6649. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6650. sleep(retryIntervalInt);
  6651. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6652. if(!isSuccess)
  6653. {
  6654. DEBUG_INFO("Diagnostics fail.\n");
  6655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6656. }
  6657. else
  6658. {
  6659. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6660. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6661. }
  6662. }
  6663. else
  6664. {
  6665. sscanf(host,"%[^/]%s",host1, path1);
  6666. sprintf(ftppath,"%s", path1);
  6667. int ftppathlen=strlen(ftppath);
  6668. int i=1;
  6669. char filenametemp[50];
  6670. while(i < ftppathlen)
  6671. {
  6672. int len=ftppathlen-i;
  6673. if(ftppath[len]== 47) // '/' ascll code: 47
  6674. {
  6675. DEBUG_INFO("find '/' all right\n");
  6676. break;
  6677. }
  6678. i=i+1;
  6679. }
  6680. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6681. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6682. filenametemp[i+1] = 0;
  6683. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6684. if(port == 0)
  6685. port = 21;
  6686. do{
  6687. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6688. sleep(retryIntervalInt);
  6689. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6690. if(!isSuccess)
  6691. {
  6692. DEBUG_INFO("Diagnostics fail.\n");
  6693. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6694. }
  6695. else
  6696. {
  6697. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6698. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6699. }
  6700. }
  6701. end:
  6702. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6703. pthread_exit(NULL);
  6704. }
  6705. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6706. {
  6707. mtrace();
  6708. int result = FAIL;
  6709. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6710. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6711. {
  6712. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6713. localversion = -1;
  6714. }
  6715. else
  6716. {
  6717. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6718. OCPP_getListVerion();
  6719. }
  6720. //from db.OCPP_getListVerion
  6721. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6722. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6723. sendGetLocalListVersionConfirmation(uuid,"");
  6724. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6725. return result;
  6726. }
  6727. int handleRemoteStartRequest(char *uuid, char *payload)
  6728. {
  6729. mtrace();
  6730. int result = FAIL;
  6731. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6732. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6733. int tempIndex = 0;
  6734. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6735. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6736. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6737. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6738. int chargingSchedulePeriodCount = 0;
  6739. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6740. int c = 0;
  6741. char *loc;
  6742. char comfirmstr[20]={0};
  6743. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6744. if(server_pending == TRUE)
  6745. {
  6746. return 0;
  6747. }
  6748. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6749. strcpy(sstrtemp, stringtrimspace(payload));
  6750. //**********connectorId****************/
  6751. c = 0;
  6752. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6753. loc = strstr(sstrtemp, "connectorId");
  6754. if(loc == NULL)
  6755. {
  6756. connectorIdIsNULL = TRUE;
  6757. }
  6758. else
  6759. {
  6760. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6761. {
  6762. sstr[c] = loc[strlen("connectorId")+2+c];
  6763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6764. c++;
  6765. }
  6766. sstr[c] = '\0';
  6767. connectorIdInt = atoi(sstr);
  6768. }
  6769. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6770. {
  6771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6772. goto end;
  6773. }
  6774. //****************idTag*******************/
  6775. c = 0;
  6776. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6777. loc = strstr(sstrtemp, "idTag");
  6778. while (loc[3+strlen("idTag")+c] != '\"')
  6779. {
  6780. sstr[c] = loc[3+strlen("idTag")+c];
  6781. c++;
  6782. }
  6783. sstr[c] = '\0';
  6784. strcpy(idTagstr,sstr);
  6785. //****************chargingProfile*******************/
  6786. c = 0;
  6787. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6788. loc = strstr(sstrtemp, "chargingProfile");
  6789. if(loc == NULL)
  6790. {
  6791. chargingProfileIsNULL = TRUE;
  6792. }
  6793. else
  6794. {
  6795. //****************chargingProfileId*******************/
  6796. c=0;
  6797. loc = strstr(sstrtemp, "chargingProfileId");
  6798. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6799. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6800. {
  6801. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6803. c++;
  6804. }
  6805. sstr[c] = '\0';
  6806. chargingProfileIdInt = atoi(sstr);
  6807. //****************transactionId*******************/
  6808. loc = strstr(sstrtemp, "transactionId");
  6809. if(loc == NULL)
  6810. {
  6811. transactionIdIsNULL = TRUE;
  6812. }
  6813. else
  6814. {
  6815. c=0;
  6816. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6817. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6818. {
  6819. sstr[c] = loc[strlen("transactionId")+2+c];
  6820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6821. c++;
  6822. }
  6823. sstr[c] = '\0';
  6824. transactionIdInt = atoi(sstr);
  6825. }
  6826. //****************stackLevel*******************/
  6827. c=0;
  6828. loc = strstr(sstrtemp, "stackLevel");
  6829. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6830. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6831. {
  6832. sstr[c] = loc[strlen("stackLevel")+2+c];
  6833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6834. c++;
  6835. }
  6836. sstr[c] = '\0';
  6837. stackLevelInt = atoi(sstr);
  6838. //****************chargingProfilePurpose*******************/
  6839. c = 0;
  6840. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6841. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6842. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6843. {
  6844. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. strcpy(chargingProfilePurposestr,sstr);
  6849. //****************chargingProfileKind*******************/
  6850. c = 0;
  6851. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6852. loc = strstr(sstrtemp, "chargingProfileKind");
  6853. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6854. {
  6855. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6856. c++;
  6857. }
  6858. sstr[c] = '\0';
  6859. strcpy(chargingProfileKindstr,sstr);
  6860. //****************recurrencyKind*******************/
  6861. loc = strstr(sstrtemp, "recurrencyKind");
  6862. if(loc == NULL)
  6863. {
  6864. recurrencyKindIsNULL = TRUE;
  6865. }
  6866. else
  6867. {
  6868. c = 0;
  6869. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6870. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6871. {
  6872. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6873. c++;
  6874. }
  6875. sstr[c] = '\0';
  6876. strcpy(recurrencyKindstr,sstr);
  6877. }
  6878. //****************validFrom*******************/
  6879. loc = strstr(sstrtemp, "validFrom");
  6880. if(loc == NULL)
  6881. {
  6882. validFromIsNULL = TRUE;
  6883. }
  6884. else
  6885. {
  6886. c = 0;
  6887. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6888. while (loc[3+strlen("validFrom")+c] != '\"')
  6889. {
  6890. sstr[c] = loc[3+strlen("validFrom")+c];
  6891. c++;
  6892. }
  6893. sstr[c] = '\0';
  6894. strcpy(validFromstr,sstr);
  6895. }
  6896. //****************validTo*******************/
  6897. loc = strstr(sstrtemp, "validTo");
  6898. if(loc == NULL)
  6899. {
  6900. validToIsNULL = TRUE;
  6901. }
  6902. else
  6903. {
  6904. c = 0;
  6905. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6906. while (loc[3+strlen("validTo")+c] != '\"')
  6907. {
  6908. sstr[c] = loc[3+strlen("validTo")+c];
  6909. c++;
  6910. }
  6911. sstr[c] = '\0';
  6912. strcpy(validTostr,sstr);
  6913. }
  6914. //****************chargingSchedule*******************/
  6915. loc = strstr(sstrtemp, "chargingSchedule");
  6916. if(loc != NULL)
  6917. {
  6918. //****************duration*******************/
  6919. loc = strstr(sstrtemp, "duration");
  6920. if(loc == NULL)
  6921. {
  6922. durationIsNULL = TRUE;
  6923. }
  6924. else
  6925. {
  6926. c=0;
  6927. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6928. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6929. {
  6930. sstr[c] = loc[strlen("duration")+2+c];
  6931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6932. c++;
  6933. }
  6934. sstr[c] = '\0';
  6935. durationInt = atoi(sstr);
  6936. }
  6937. //****************startSchedule******************/
  6938. loc = strstr(sstrtemp, "startSchedule");
  6939. if(loc == NULL)
  6940. {
  6941. startScheduleIsNULL = TRUE;
  6942. }
  6943. else
  6944. {
  6945. c = 0;
  6946. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6947. while (loc[3+strlen("startSchedule")+c] != '\"')
  6948. {
  6949. sstr[c] = loc[3+strlen("startSchedule")+c];
  6950. c++;
  6951. }
  6952. sstr[c] = '\0';
  6953. strcpy(startSchedulestr,sstr);
  6954. }
  6955. //****************chargingRateUnit*******************/
  6956. c = 0;
  6957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6958. loc = strstr(sstrtemp, "chargingRateUnit");
  6959. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6960. {
  6961. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6962. c++;
  6963. }
  6964. sstr[c] = '\0';
  6965. strcpy(chargingRateUnitstr,sstr);
  6966. //****************minChargingRate*******************/
  6967. loc = strstr(sstrtemp, "minChargingRate");
  6968. if(loc == NULL)
  6969. {
  6970. minChargingRateIsNULL = TRUE;
  6971. }
  6972. else
  6973. {
  6974. c=0;
  6975. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6976. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6977. {
  6978. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6980. c++;
  6981. }
  6982. sstr[c] = '\0';
  6983. minChargingRateflaot = atof(sstr);
  6984. }
  6985. //****************chargingSchedulePeriod count*******************/
  6986. int what_len = strlen("startPeriod");
  6987. char *where = sstrtemp;
  6988. while ((where = strstr(where, "startPeriod"))) {
  6989. where += what_len;
  6990. chargingSchedulePeriodCount++;
  6991. }
  6992. where = sstrtemp;
  6993. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6994. {
  6995. //****************startPeriod*******************/
  6996. c=0;
  6997. loc = strstr(where, "startPeriod");
  6998. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6999. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7000. {
  7001. sstr[c] = loc[strlen("startPeriod")+2+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. startPeriodInt[periodNums] = atoi(sstr);
  7007. //****************limit*******************/
  7008. c=0;
  7009. loc = strstr(where, "limit");
  7010. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7011. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7012. {
  7013. sstr[c] = loc[strlen("limit")+2+c];
  7014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7015. c++;
  7016. }
  7017. sstr[c] = '\0';
  7018. limitflaot[periodNums] = atof(sstr);
  7019. //****************numberPhases*******************/
  7020. loc = strstr(where, "numberPhases");
  7021. if(loc == NULL)
  7022. {
  7023. numberPhasesIsNULL = TRUE;
  7024. }
  7025. else
  7026. {
  7027. c=0;
  7028. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7029. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7030. {
  7031. sstr[c] = loc[strlen("numberPhases")+2+c];
  7032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7033. c++;
  7034. }
  7035. sstr[c] = '\0';
  7036. numberPhasesInt[periodNums] = atoi(sstr);
  7037. }
  7038. where = loc;
  7039. } // END FOR chargingSchedulePeriodCount
  7040. }// END IF chargingSchedule
  7041. } // END chargingProfile
  7042. /*
  7043. enum _SYSTEM_STATUS
  7044. {
  7045. S_BOOTING = 0,
  7046. S_IDLE, = 1
  7047. S_AUTHORIZING, =2
  7048. S_REASSIGN_CHECK, =3
  7049. S_REASSIGN, =4
  7050. S_PRECHARGE, =5
  7051. S_PREPARING_FOR_EV, =6
  7052. S_PREPARING_FOR_EVSE, =7
  7053. S_CHARGING, =8
  7054. S_TERMINATING, =9
  7055. S_COMPLETE, =10
  7056. S_ALARM, =11
  7057. S_FAULT =12
  7058. }
  7059. */
  7060. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7063. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7064. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7065. //check Transaction active
  7066. if(gunType[connectorIdInt -1] == 'J')
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7069. {
  7070. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = connectorIdInt -1;
  7075. }
  7076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7079. {
  7080. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7081. {
  7082. //Reserved
  7083. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7084. }
  7085. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7086. {
  7087. //Reserved
  7088. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7090. goto end;
  7091. }
  7092. else
  7093. {
  7094. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7096. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7098. {
  7099. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7100. goto end;
  7101. }
  7102. }//END FOR ELSE
  7103. }
  7104. }// END FOR CHAdeMO_QUANTITY
  7105. }
  7106. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7107. {
  7108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7109. {
  7110. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7111. }
  7112. else
  7113. {
  7114. tempIndex = connectorIdInt -1;
  7115. }
  7116. for (int index = 0; index < CCS_QUANTITY; index++)
  7117. {
  7118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7119. {
  7120. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7121. {
  7122. //Reserved
  7123. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7124. }
  7125. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7126. {
  7127. //Reserved
  7128. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7130. goto end;
  7131. }
  7132. else
  7133. {
  7134. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7135. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7136. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7137. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7138. {
  7139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7140. goto end;
  7141. }
  7142. }// END FOR ELSE
  7143. }
  7144. }// END FOR CCS_QUANTITY
  7145. }
  7146. else if(gunType[connectorIdInt -1] == 'G')
  7147. {
  7148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7149. {
  7150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7151. }
  7152. else
  7153. {
  7154. tempIndex = connectorIdInt -1;
  7155. }
  7156. for (int index = 0; index < GB_QUANTITY; index++)
  7157. {
  7158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7159. {
  7160. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7161. {
  7162. //Reserved
  7163. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7164. }
  7165. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7166. {
  7167. //Reserved
  7168. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7169. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7170. goto end;
  7171. }
  7172. else
  7173. {
  7174. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7175. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7176. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7177. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7178. {
  7179. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7180. goto end;
  7181. }
  7182. }// END FOR ELSE
  7183. }
  7184. } // END FOR GB_QUANTITY
  7185. }
  7186. else
  7187. {
  7188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7189. {
  7190. tempIndex = 2;
  7191. }
  7192. else
  7193. {
  7194. tempIndex = connectorIdInt -1;
  7195. }
  7196. for (int index = 0; index < AC_QUANTITY; index++)
  7197. {
  7198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7199. {
  7200. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7201. {
  7202. //Reserved
  7203. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7204. }
  7205. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7206. {
  7207. //Reserved
  7208. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7210. goto end;
  7211. }
  7212. else
  7213. {
  7214. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7215. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7216. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7217. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7218. {
  7219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7220. goto end;
  7221. }
  7222. }//END FOR ELSE
  7223. }
  7224. }// END FOR AC_QUANTITY
  7225. }
  7226. if(chargingProfileIsNULL == FALSE)
  7227. {
  7228. //ChargingProfile
  7229. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7230. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7231. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7232. if(recurrencyKindIsNULL == FALSE) //OPTION
  7233. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7234. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7235. if(transactionIdIsNULL == FALSE) // OPTION
  7236. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7237. if(validFromIsNULL == FALSE) // OPTION
  7238. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7239. if(validToIsNULL == FALSE) //OPTION
  7240. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7241. //ChargingSchedule
  7242. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7243. if(durationIsNULL == FALSE) //OPTION
  7244. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7245. if(minChargingRateIsNULL == FALSE) //OPTION
  7246. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7247. if(startScheduleIsNULL == FALSE) //OPTION
  7248. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7249. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7250. {
  7251. //ChargingSchedulePeriod
  7252. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7253. if(numberPhasesIsNULL == FALSE)
  7254. {
  7255. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7256. }
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7258. }
  7259. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7260. {
  7261. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7263. //memset idTag
  7264. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7265. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7266. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7267. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7268. }
  7269. else
  7270. {
  7271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7272. }
  7273. }
  7274. else
  7275. {
  7276. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7278. //memset idTag
  7279. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7280. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7281. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7282. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7283. }
  7284. }
  7285. else
  7286. {
  7287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7288. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7289. }
  7290. end:
  7291. if(connectorIdIsNULL == FALSE)
  7292. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7293. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7294. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7295. //OCPP send RemoteStartConfirmation by first.
  7296. sendRemoteStartConfirmation(uuid, comfirmstr);
  7297. return result;
  7298. }
  7299. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. int match = FALSE;
  7304. int GunNO = 0;
  7305. int tempIndex = 0;
  7306. int transactionIdInt=0;
  7307. int transactionIdIsNULL= FALSE;
  7308. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7309. int c = 0;
  7310. char *loc;
  7311. char comfirmstr[20];
  7312. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7313. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7314. if(server_pending == TRUE)
  7315. {
  7316. return 0;
  7317. }
  7318. strcpy(sstrtemp, stringtrimspace(payload));
  7319. c=0;
  7320. loc = strstr(sstrtemp, "transactionId");
  7321. if(loc == NULL)
  7322. {
  7323. transactionIdIsNULL= TRUE;
  7324. }
  7325. else
  7326. {
  7327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7328. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7329. {
  7330. sstr[c] = loc[strlen("transactionId")+2+c];
  7331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. transactionIdInt = atoi(sstr);
  7336. }
  7337. if(transactionIdIsNULL == FALSE)
  7338. {
  7339. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7340. {
  7341. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7342. {
  7343. //check Transaction active
  7344. if(gunType[gun_index] == 'J')
  7345. {
  7346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7347. {
  7348. tempIndex = ((gun_index==2) ? 1: 0);
  7349. }
  7350. else
  7351. {
  7352. tempIndex = gun_index;
  7353. }
  7354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7355. {
  7356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7357. {
  7358. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7359. {
  7360. match = TRUE;
  7361. GunNO = gun_index;
  7362. }
  7363. }
  7364. }// END FOR CHAdeMO_QUANTITY
  7365. }
  7366. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7367. {
  7368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7369. {
  7370. tempIndex = ((gun_index==2) ? 1: 0);
  7371. }
  7372. else
  7373. {
  7374. tempIndex = gun_index;
  7375. }
  7376. for (int index = 0; index < CCS_QUANTITY; index++)
  7377. {
  7378. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7379. {
  7380. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7381. {
  7382. match = TRUE;
  7383. GunNO = gun_index;
  7384. }
  7385. }
  7386. }// END FOR CCS_QUANTITY
  7387. }
  7388. else if(gunType[gun_index] == 'G')
  7389. {
  7390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7391. {
  7392. tempIndex = ((gun_index==2) ? 1: 0);
  7393. }
  7394. else
  7395. {
  7396. tempIndex = gun_index;
  7397. }
  7398. for (int index = 0; index < GB_QUANTITY; index++)
  7399. {
  7400. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7401. {
  7402. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7403. {
  7404. match = TRUE;
  7405. GunNO = gun_index;
  7406. }
  7407. }
  7408. }// END FOR GB_QUANTITY
  7409. }
  7410. else
  7411. {
  7412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7413. {
  7414. tempIndex = 2;
  7415. }
  7416. else
  7417. {
  7418. tempIndex = gun_index;
  7419. }
  7420. for (int index = 0; index < AC_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7423. {
  7424. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7425. {
  7426. match = TRUE;
  7427. GunNO = gun_index;
  7428. }
  7429. }
  7430. }// END FOR CHAdeMO_QUANTITY
  7431. } // END FOR AC ELSE
  7432. }// CHECK IF ResponseTransactionId == transactionIdInt
  7433. }//END FOR
  7434. if( match == TRUE)
  7435. {
  7436. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7438. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7439. }
  7440. else
  7441. {
  7442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7443. }
  7444. }
  7445. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7446. return result;
  7447. }
  7448. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7449. {
  7450. mtrace();
  7451. int result = FAIL;
  7452. int connectorIdInt=0, reservationIdInt=0;
  7453. int tempIndex = 0;
  7454. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7455. char comfirmstr[20]={0};
  7456. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7457. int c = 0;
  7458. char *loc;
  7459. //char *ptr;
  7460. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7461. strcpy(sstrtemp, stringtrimspace(payload));
  7462. //***(1)connectorId ****/
  7463. c=0;
  7464. loc = strstr(sstrtemp, "connectorId");
  7465. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7466. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7467. {
  7468. sstr[c] = loc[strlen("connectorId")+2+c];
  7469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7470. c++;
  7471. }
  7472. sstr[c] = '\0';
  7473. connectorIdInt = atoi(sstr);
  7474. //***(2)expiryDate ****/
  7475. loc = strstr(sstrtemp, "expiryDate");
  7476. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7477. c = 0;
  7478. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7479. {
  7480. sstr[c] = loc[3+strlen("expiryDate")+c];
  7481. c++;
  7482. }
  7483. sstr[c] = '\0';
  7484. strcpy(expiryDatestr, sstr);
  7485. //***(3)idTag ****/
  7486. loc = strstr(sstrtemp, "idTag");
  7487. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7488. c = 0;
  7489. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7490. {
  7491. sstr[c] = loc[3+strlen("idTag")+c];
  7492. c++;
  7493. }
  7494. sstr[c] = '\0';
  7495. strcpy(idTagstr, sstr);
  7496. //***(4)parentIdTag ****/
  7497. loc = strstr(sstrtemp, "parentIdTag");
  7498. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7499. c = 0;
  7500. if(loc == NULL)
  7501. {
  7502. strcpy(parentIdTagstr, "");
  7503. }
  7504. else
  7505. {
  7506. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7507. {
  7508. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7509. c++;
  7510. }
  7511. sstr[c] = '\0';
  7512. strcpy(parentIdTagstr, sstr);
  7513. }
  7514. //***(5)reservationId ****/
  7515. c=0;
  7516. loc = strstr(sstrtemp, "reservationId");
  7517. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7518. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7519. {
  7520. sstr[c] = loc[strlen("reservationId")+2+c];
  7521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7522. c++;
  7523. }
  7524. sstr[c] = '\0';
  7525. reservationIdInt = atoi(sstr);
  7526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7527. /*
  7528. enum SYSTEM_STATUS
  7529. {
  7530. SYS_MODE_BOOTING = 0,
  7531. SYS_MODE_IDLE = 1,
  7532. SYS_MODE_AUTHORIZING = 2,
  7533. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7534. SYS_MODE_REASSIGN = 4,
  7535. SYS_MODE_PREPARING = 5,
  7536. SYS_MODE_PREPARE_FOR_EV = 6,
  7537. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7538. SYS_MODE_CHARGING = 8,
  7539. SYS_MODE_TERMINATING = 9,
  7540. SYS_MODE_COMPLETE = 10,
  7541. SYS_MODE_ALARM = 11,
  7542. SYS_MODE_FAULT = 12,
  7543. SYS_MODE_RESERVATION = 13,
  7544. SYS_MODE_BOOKING = 14,
  7545. SYS_MODE_MAINTAIN = 15,
  7546. SYS_MODE_DEBUG = 16,
  7547. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7548. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7549. SYS_MODE_UPDATE = 19
  7550. };
  7551. */
  7552. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7553. {
  7554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7555. goto end;
  7556. }
  7557. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7558. {
  7559. //check Transaction active
  7560. if(gunType[connectorIdInt -1] == 'J')
  7561. {
  7562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7563. {
  7564. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7565. }
  7566. else
  7567. {
  7568. tempIndex = connectorIdInt -1;
  7569. }
  7570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7571. {
  7572. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7573. {
  7574. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7575. {
  7576. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7577. {
  7578. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7579. {
  7580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7582. }
  7583. 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'))
  7584. {
  7585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7586. }
  7587. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7588. {
  7589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7590. }
  7591. else
  7592. {
  7593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7594. }
  7595. }
  7596. 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
  7597. {
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7599. }
  7600. }
  7601. else
  7602. {
  7603. //replace reservation
  7604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7606. }
  7607. }
  7608. } // END FOR CHAdeMO_QUANTITY
  7609. }
  7610. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7611. {
  7612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7613. {
  7614. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7615. }
  7616. else
  7617. {
  7618. tempIndex = connectorIdInt -1;
  7619. }
  7620. for (int index = 0; index < CCS_QUANTITY; index++)
  7621. {
  7622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7623. {
  7624. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7625. {
  7626. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7627. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7630. {
  7631. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7633. }
  7634. 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'))
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7637. }
  7638. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7639. {
  7640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7641. }
  7642. else
  7643. {
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7645. }
  7646. }
  7647. 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
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7650. }
  7651. }
  7652. else
  7653. {
  7654. //replace reservation
  7655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7657. }
  7658. }
  7659. } // END FOR CCS_QUANTITY
  7660. }
  7661. else if(gunType[connectorIdInt -1] == 'G')
  7662. {
  7663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7664. {
  7665. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7666. }
  7667. else
  7668. {
  7669. tempIndex = connectorIdInt -1;
  7670. }
  7671. for (int index = 0; index < GB_QUANTITY; index++)
  7672. {
  7673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7674. {
  7675. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7676. {
  7677. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7678. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7679. {
  7680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7681. {
  7682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7684. }
  7685. 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'))
  7686. {
  7687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7692. }
  7693. else
  7694. {
  7695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7696. }
  7697. }
  7698. 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
  7699. {
  7700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7701. }
  7702. }
  7703. else
  7704. {
  7705. //replace reservation
  7706. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7708. }
  7709. }
  7710. }// END FOR GB_QUANTITY
  7711. }
  7712. else
  7713. {
  7714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7715. {
  7716. tempIndex = 2;
  7717. }
  7718. else
  7719. {
  7720. tempIndex = (connectorIdInt -1);
  7721. }
  7722. for (int index = 0; index < AC_QUANTITY; index++)
  7723. {
  7724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7725. {
  7726. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7727. {
  7728. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7729. {
  7730. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7731. {
  7732. 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))
  7733. {
  7734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7735. }
  7736. else
  7737. {
  7738. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7740. }
  7741. }
  7742. 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'))
  7743. {
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7745. }
  7746. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7747. {
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7749. }
  7750. else
  7751. {
  7752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7753. }
  7754. }
  7755. 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
  7756. {
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7758. }
  7759. }
  7760. else
  7761. {
  7762. //replace reservation
  7763. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7765. }
  7766. }
  7767. } // END FOR AC_QUANTITY
  7768. }
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7770. }
  7771. else if(connectorIdInt == 0)
  7772. {
  7773. //check Transaction active
  7774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7775. {
  7776. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7777. {
  7778. 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'))
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7781. goto end;
  7782. }
  7783. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7784. {
  7785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7786. goto end;
  7787. }
  7788. 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
  7789. {
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7791. goto end;
  7792. }
  7793. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7796. goto end;
  7797. }
  7798. }
  7799. }// END FOR CHAdeMO_QUANTITY
  7800. for (int index = 0; index < CCS_QUANTITY; index++)
  7801. {
  7802. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7803. {
  7804. 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'))
  7805. {
  7806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7807. goto end;
  7808. }
  7809. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7810. {
  7811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7812. goto end;
  7813. }
  7814. 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
  7815. {
  7816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7817. goto end;
  7818. }
  7819. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7820. {
  7821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7822. goto end;
  7823. }
  7824. }
  7825. } // END FOR CCS_QUANTITY
  7826. for (int index = 0; index < GB_QUANTITY; index++)
  7827. {
  7828. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7829. {
  7830. 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'))
  7831. {
  7832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7833. goto end;
  7834. }
  7835. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7836. {
  7837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7838. goto end;
  7839. }
  7840. 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
  7841. {
  7842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7843. goto end;
  7844. }
  7845. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7846. {
  7847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7848. goto end;
  7849. }
  7850. }
  7851. } // END FOR GB_QUANTITY
  7852. for (int index = 0; index < AC_QUANTITY; index++)
  7853. {
  7854. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7855. {
  7856. 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'))
  7857. {
  7858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7859. goto end;
  7860. }
  7861. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7862. {
  7863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7864. goto end;
  7865. }
  7866. 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
  7867. {
  7868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7869. goto end;
  7870. }
  7871. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7872. {
  7873. 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))
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7876. goto end;
  7877. }
  7878. }
  7879. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7880. {
  7881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7882. goto end;
  7883. }
  7884. }
  7885. }// END FOR AC_QUANTITY
  7886. //The connectorId is 0
  7887. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7889. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7890. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7891. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7892. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7893. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7894. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7895. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7896. result = TRUE;
  7897. return result;
  7898. }
  7899. else
  7900. {
  7901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7902. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7903. }
  7904. if(strcmp(comfirmstr,"Accepted") == 0)
  7905. {
  7906. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7907. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7908. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7909. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7910. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7911. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7912. result = TRUE;
  7913. return result;
  7914. }
  7915. end:
  7916. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7917. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7918. return result;
  7919. }
  7920. int handleResetRequest(char *uuid, char *payload)
  7921. {
  7922. mtrace();
  7923. int result = FAIL;
  7924. char sstr[10]={0},sstrtemp[30]={ 0 };
  7925. char typestr[10]={0};
  7926. char comfirmstr[20]={0};
  7927. int c = 0;
  7928. char *loc;
  7929. DEBUG_INFO("handleResetRequest...\n");
  7930. strcpy(sstrtemp, stringtrimspace(payload));
  7931. loc = strstr(sstrtemp, "type");
  7932. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7933. c = 0;
  7934. while (loc[3+strlen("type")+c] != '\"')
  7935. {
  7936. sstr[c] = loc[3+strlen("type")+c];
  7937. c++;
  7938. }
  7939. sstr[c] = '\0';
  7940. strcpy(typestr,sstr);
  7941. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7942. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7943. {
  7944. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7945. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7946. result = TRUE;
  7947. return result;
  7948. }
  7949. else
  7950. {
  7951. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7952. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7953. goto errorend;
  7954. }
  7955. errorend:
  7956. sendResetConfirmation(uuid, comfirmstr);
  7957. return result;
  7958. }
  7959. int handleSendLocalListRequest(char *uuid, char *payload)
  7960. {
  7961. mtrace();
  7962. int result = FAIL;
  7963. int listVersionInt;
  7964. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7965. char listsearch[]="listVersion";
  7966. char updateTypesearch[]="updateType";
  7967. char localAuthorizationListsearch[]="localAuthorizationList";
  7968. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7969. char CardList[500][160]={0};
  7970. char updateTypestr[15]={0};
  7971. char idTagstr[20]={0};
  7972. char parentIdTag[20]={0};
  7973. char expiryDate[30]={0};
  7974. char idTagstatus[16]={0};
  7975. int c = 0;
  7976. int i = 0;
  7977. char *delim1 = "}";
  7978. char * pch;
  7979. char *loc;
  7980. //char *ptr;
  7981. char comfirmstr[20];
  7982. //int n_localAuthorizations = 0;
  7983. int checkState_Faulted = FALSE;
  7984. DEBUG_INFO("handleSendLocalListRequest...\n");
  7985. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7986. {
  7987. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7988. goto end;
  7989. }
  7990. //check Charge Point state
  7991. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7992. {
  7993. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7994. {
  7995. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7996. }
  7997. }
  7998. for (int index = 0; index < CCS_QUANTITY; index++)
  7999. {
  8000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8001. {
  8002. checkState_Faulted = TRUE; //OCPP Status
  8003. }
  8004. }
  8005. for (int index = 0; index < GB_QUANTITY; index++)
  8006. {
  8007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8008. {
  8009. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8010. }
  8011. }
  8012. //check Charge Point state
  8013. for (int index = 0; index < AC_QUANTITY; index++)
  8014. {
  8015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8016. {
  8017. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8018. }
  8019. }
  8020. if(checkState_Faulted == TRUE)
  8021. {
  8022. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8023. goto end;
  8024. }
  8025. //Filter payload space
  8026. strcpy(sstrtemp, stringtrimspace(payload));
  8027. //listVersion
  8028. c = 0;
  8029. loc = strstr(sstrtemp, listsearch);
  8030. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8031. {
  8032. sstr[c] = loc[strlen("listVersion")+2+c];
  8033. c++;
  8034. }
  8035. sstr[c] = '\0';
  8036. listVersionInt = atoi(sstr);
  8037. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8038. //updateType
  8039. loc = strstr(sstrtemp, updateTypesearch);
  8040. c = 0;
  8041. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8042. {
  8043. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8044. c++;
  8045. }
  8046. sstr[c] = '\0';
  8047. strcpy(updateTypestr, sstr);
  8048. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8049. //localAuthorizationList
  8050. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8051. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8052. if(loc != NULL) // localAuthorizationList is not NULL
  8053. {
  8054. //Check UpdateType
  8055. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8056. {
  8057. //Local list full update
  8058. printf("Local list full update.\n");
  8059. OCPP_getListVerion();
  8060. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8061. {
  8062. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8063. goto end;
  8064. }
  8065. OCPP_cleanLocalList();
  8066. }
  8067. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8068. {
  8069. //Local list different update
  8070. printf("Local list different update.\n");
  8071. OCPP_getListVerion();
  8072. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8073. {
  8074. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8075. goto end;
  8076. }
  8077. }
  8078. else
  8079. {
  8080. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8081. goto end;
  8082. }
  8083. c = 0;
  8084. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8085. {
  8086. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8087. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8088. c++;
  8089. }
  8090. sstr[c] = '\0';
  8091. //DEBUG_INFO("sstr=%s\n", sstr);
  8092. //parsing strings to words
  8093. i = 0;
  8094. pch = strtok(sstr,delim1);
  8095. while (pch != NULL)
  8096. {
  8097. strcpy(CardList[i], pch);
  8098. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8099. pch = strtok (NULL, delim1);
  8100. i = i + 1;
  8101. }
  8102. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8103. //local Authorizations List Numbers
  8104. //n_localAuthorizations = i;
  8105. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8106. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8107. c= 0;
  8108. while(c < i) // i is CardList Number
  8109. {
  8110. //Search "IdToken"
  8111. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8112. loc = strstr(CardList[c], "idTag");
  8113. int j = 0;
  8114. while (loc[3+strlen("idTag")+j] != '\"')
  8115. {
  8116. sstr[j] = loc[3+strlen("idTag")+j];
  8117. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8118. j++;
  8119. }
  8120. sstr[j] = '\0';
  8121. strcpy(idTagstr, sstr);
  8122. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8123. //Search "expiryDate"
  8124. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8125. loc = strstr(CardList[c], "expiryDate");
  8126. j = 0;
  8127. if(loc != NULL)
  8128. {
  8129. while (loc[3+strlen("expiryDate")+j] != '\"')
  8130. {
  8131. sstr[j] = loc[3+strlen("expiryDate")+j];
  8132. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8133. j++;
  8134. }
  8135. sstr[j] = '\0';
  8136. strcpy(expiryDate, sstr);
  8137. }
  8138. else
  8139. {
  8140. strcpy(expiryDate, "");
  8141. }
  8142. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8143. //Search "parentIdTag"
  8144. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8145. loc = strstr(CardList[c], "parentIdTag");
  8146. j = 0;
  8147. if(loc != NULL)
  8148. {
  8149. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8150. {
  8151. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8152. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8153. j++;
  8154. }
  8155. sstr[j] = '\0';
  8156. strcpy(parentIdTag, sstr);
  8157. }
  8158. else
  8159. {
  8160. strcpy(parentIdTag, "");
  8161. }
  8162. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8163. //Search "status"
  8164. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8165. loc = strstr(CardList[c], "status");
  8166. j = 0;
  8167. while (loc[3+strlen("status")+j] != '\"')
  8168. {
  8169. sstr[j] = loc[3+strlen("status")+j];
  8170. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8171. j++;
  8172. }
  8173. sstr[j] = '\0';
  8174. strcpy(idTagstatus, sstr);
  8175. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8176. OCPP_getIdTag(idTagstr);
  8177. //OCPP_getIdTag("test"); For Test
  8178. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8179. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8180. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8181. {
  8182. //Local list full update
  8183. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8184. // update list
  8185. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8186. //DEBUG_INFO("Local list full update. 1\n");
  8187. //OCPP_get_TableAuthlocalAllData();
  8188. //DEBUG_INFO("Local list full update. 2\n");
  8189. }
  8190. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8191. {
  8192. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8193. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8194. }
  8195. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8196. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8197. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8198. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8199. c++;
  8200. }
  8201. }
  8202. else
  8203. {
  8204. //Check UpdateType
  8205. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8206. {
  8207. //Local list full update
  8208. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8209. OCPP_cleanLocalList();
  8210. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8211. goto end;
  8212. }
  8213. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8214. {
  8215. //Local list different update
  8216. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8217. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8218. goto end;
  8219. }
  8220. }
  8221. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8222. end:
  8223. sendSendLocalListConfirmation(uuid, comfirmstr);
  8224. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8225. return result;
  8226. }
  8227. #define MAX 200
  8228. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8229. {
  8230. mtrace();
  8231. int result = FAIL;
  8232. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8233. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8234. char chargingProfilePurposeStr[30]={0};
  8235. char chargingProfileKindStr[16]={0};
  8236. char recurrencyKindStr[10]={0};
  8237. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8238. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8239. int chargingSchedulePeriodCount = 0;
  8240. //int updateflag = FALSE;
  8241. char comfirmstr[20]={0};
  8242. int meet= FALSE;
  8243. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8244. int c = 0;
  8245. char *loc;
  8246. FILE *fptr1;//, *fptr2;
  8247. //int lno=0;//, linectr = 0;
  8248. //int modifyflag = FALSE;
  8249. char filename[MAX]={0};
  8250. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8251. //int resultRename=0;
  8252. char rmFileCmd[50]={0};
  8253. char tempchargingProfilePurposeStr[30]={0};
  8254. char word[1600]={0};
  8255. int n_chargingProfile = 0;
  8256. //[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}}}]
  8257. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8258. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8259. //Filter string space
  8260. strcpy(sstrtemp, stringtrimspace(payload));
  8261. //*********************connectorId***************************/
  8262. loc = strstr(sstrtemp, "connectorId");
  8263. c = 0;
  8264. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8265. while (loc[strlen("connectorId")+2+c] != ',')
  8266. {
  8267. sstr[c] = loc[strlen("connectorId")+2+c];
  8268. c++;
  8269. }
  8270. sstr[c] = '\0';
  8271. connectorIdInt = atoi(sstr);
  8272. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8273. {
  8274. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8275. }
  8276. else
  8277. {
  8278. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8279. }
  8280. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8281. //*********************chargingProfileId***************************/
  8282. loc = strstr(sstrtemp, "chargingProfileId");
  8283. c = 0;
  8284. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8285. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8286. {
  8287. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8288. c++;
  8289. }
  8290. sstr[c] = '\0';
  8291. chargingProfileIdInt = atoi(sstr);
  8292. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8293. {
  8294. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8295. }
  8296. else
  8297. {
  8298. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8299. }
  8300. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8301. //*********************transactionId***************************/
  8302. loc = strstr(sstrtemp, "transactionId");
  8303. if(loc != NULL)
  8304. {
  8305. c = 0;
  8306. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8307. while (loc[strlen("transactionId")+2+c] != ',')
  8308. {
  8309. sstr[c] = loc[strlen("transactionId")+2+c];
  8310. c++;
  8311. }
  8312. sstr[c] = '\0';
  8313. transactionIdInt = atoi(sstr);
  8314. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8315. {
  8316. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8317. }
  8318. else
  8319. {
  8320. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8321. }
  8322. }
  8323. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8324. //*********************stackLevel***************************/
  8325. loc = strstr(sstrtemp, "stackLevel");
  8326. c = 0;
  8327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8328. while (loc[strlen("stackLevel")+2+c] != ',')
  8329. {
  8330. sstr[c] = loc[strlen("stackLevel")+2+c];
  8331. c++;
  8332. }
  8333. sstr[c] = '\0';
  8334. stackLevelInt = atoi(sstr);
  8335. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8336. {
  8337. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8338. }
  8339. else
  8340. {
  8341. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8342. }
  8343. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8344. //*********************chargingProfilePurpose***************************/
  8345. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8346. c = 0;
  8347. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8348. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8349. {
  8350. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8351. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8352. c++;
  8353. }
  8354. sstr[c] = '\0';
  8355. strcpy(chargingProfilePurposeStr,sstr);
  8356. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8358. {
  8359. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8360. }
  8361. else
  8362. {
  8363. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8364. }
  8365. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8366. //*********************chargingProfileKind***************************/
  8367. loc = strstr(sstrtemp, "chargingProfileKind");
  8368. c = 0;
  8369. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8370. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8371. {
  8372. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8373. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8374. c++;
  8375. }
  8376. sstr[c] = '\0';
  8377. strcpy(chargingProfileKindStr,sstr);
  8378. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8379. {
  8380. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8381. }
  8382. else
  8383. {
  8384. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8385. }
  8386. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8387. //*********************recurrencyKind***************************/
  8388. loc = strstr(sstrtemp, "recurrencyKind");
  8389. if(loc != NULL)
  8390. {
  8391. c = 0;
  8392. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8393. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8394. {
  8395. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8397. c++;
  8398. }
  8399. sstr[c] = '\0';
  8400. strcpy(recurrencyKindStr,sstr);
  8401. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8402. {
  8403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8404. }
  8405. else
  8406. {
  8407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8408. }
  8409. }
  8410. else
  8411. {
  8412. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8413. {
  8414. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8415. }
  8416. else
  8417. {
  8418. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8419. }
  8420. }
  8421. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8422. //*********************validFrom***************************/
  8423. loc = strstr(sstrtemp, "validFrom");
  8424. if(loc != NULL)
  8425. {
  8426. c = 0;
  8427. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8428. while (loc[3+strlen("validFrom")+c] != '\"')
  8429. {
  8430. sstr[c] = loc[3+strlen("validFrom")+c];
  8431. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8432. c++;
  8433. }
  8434. sstr[c] = '\0';
  8435. strcpy(validFromStr,sstr);
  8436. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8437. {
  8438. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8439. }
  8440. else
  8441. {
  8442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8443. }
  8444. }
  8445. else
  8446. {
  8447. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8448. {
  8449. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8450. }
  8451. else
  8452. {
  8453. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8454. }
  8455. }
  8456. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8457. //*********************validTo***************************/
  8458. loc = strstr(sstrtemp, "validTo");
  8459. if(loc != NULL)
  8460. {
  8461. c = 0;
  8462. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8463. while (loc[3+strlen("validTo")+c] != '\"')
  8464. {
  8465. sstr[c] = loc[3+strlen("validTo")+c];
  8466. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8467. c++;
  8468. }
  8469. sstr[c] = '\0';
  8470. strcpy(validToStr,sstr);
  8471. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8472. {
  8473. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8474. }
  8475. else
  8476. {
  8477. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8478. }
  8479. }
  8480. else
  8481. {
  8482. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8483. {
  8484. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8485. }
  8486. else
  8487. {
  8488. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8489. }
  8490. }
  8491. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8492. //*********************duration***************************/
  8493. loc = strstr(sstrtemp, "duration");
  8494. if(loc != NULL)
  8495. {
  8496. c = 0;
  8497. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8498. while (loc[strlen("duration")+2+c] != ',')
  8499. {
  8500. sstr[c] = loc[strlen("duration")+2+c];
  8501. c++;
  8502. }
  8503. sstr[c] = '\0';
  8504. durationInt = atoi(sstr);
  8505. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8506. {
  8507. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8508. }
  8509. else
  8510. {
  8511. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8512. }
  8513. }
  8514. else
  8515. {
  8516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8517. {
  8518. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8519. }
  8520. else
  8521. {
  8522. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8523. }
  8524. }
  8525. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8526. //*********************startSchedule***************************/
  8527. loc = strstr(sstrtemp, "startSchedule");
  8528. if(loc != NULL)
  8529. {
  8530. c = 0;
  8531. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8532. while (loc[3+strlen("startSchedule")+c] != '\"')
  8533. {
  8534. sstr[c] = loc[3+strlen("startSchedule")+c];
  8535. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8536. c++;
  8537. }
  8538. sstr[c] = '\0';
  8539. strcpy(startScheduleStr,sstr);
  8540. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8541. {
  8542. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8543. }
  8544. else
  8545. {
  8546. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8547. }
  8548. }
  8549. else
  8550. {
  8551. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8552. {
  8553. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8554. }
  8555. else
  8556. {
  8557. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8558. }
  8559. }
  8560. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8561. //*********************chargingRateUnit***************************/
  8562. loc = strstr(sstrtemp, "chargingRateUnit");
  8563. if(loc != NULL)
  8564. {
  8565. c = 0;
  8566. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8567. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8568. {
  8569. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8570. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8571. c++;
  8572. }
  8573. sstr[c] = '\0';
  8574. strcpy(chargingRateUnitStr,sstr);
  8575. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8576. {
  8577. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8578. }
  8579. else
  8580. {
  8581. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8582. }
  8583. }
  8584. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8585. //****************chargingSchedulePeriod count start*******************/
  8586. int what_len = strlen("startPeriod");
  8587. char tempChargingProfile[1600]={0};
  8588. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8589. char *where = tempChargingProfile;
  8590. if (what_len)
  8591. {
  8592. while ((where = strstr(where, "startPeriod"))) {
  8593. where += what_len;
  8594. chargingSchedulePeriodCount++;
  8595. }
  8596. }
  8597. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8598. {
  8599. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8600. goto end;
  8601. }
  8602. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8603. //where = payload;
  8604. int templength = 0;
  8605. //int searchstart = 0;
  8606. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8607. {
  8608. //****************startPeriod*******************/
  8609. c=0;
  8610. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8611. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8612. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8613. {
  8614. sstr[c] = loc[strlen("startPeriod")+2+c];
  8615. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8616. c++;
  8617. }
  8618. sstr[c] = '\0';
  8619. startPeriodInt[periodNums] = atoi(sstr);
  8620. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8621. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8622. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8623. {
  8624. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8625. }
  8626. else
  8627. {
  8628. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8629. }
  8630. templength = strlen("startPeriod")+2+c;
  8631. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8632. //****************limit*******************/
  8633. c=0;
  8634. loc = strstr(tempChargingProfile + templength, "limit");
  8635. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8636. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8637. {
  8638. sstr[c] = loc[strlen("limit")+2+c];
  8639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8640. c++;
  8641. }
  8642. sstr[c] = '\0';
  8643. limitflaot[periodNums] = atof(sstr);
  8644. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8645. {
  8646. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8647. }
  8648. else
  8649. {
  8650. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8651. }
  8652. templength = templength + strlen("limit")+2+c;
  8653. //****************numberPhases*******************/
  8654. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8655. if(loc != NULL)
  8656. {
  8657. c=0;
  8658. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8659. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8660. {
  8661. sstr[c] = loc[strlen("numberPhases")+2+c];
  8662. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8663. c++;
  8664. }
  8665. sstr[c] = '\0';
  8666. numberPhasesInt[periodNums] = atoi(sstr);
  8667. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8668. {
  8669. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8670. }
  8671. else
  8672. {
  8673. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8674. }
  8675. templength = templength + strlen("numberPhases")+2+c;
  8676. }
  8677. //where = loc;
  8678. }
  8679. //****************chargingSchedulePeriod count end*******************/
  8680. //*********************minChargingRate***************************/
  8681. loc = strstr(sstrtemp, "minChargingRate");
  8682. if(loc != NULL)
  8683. {
  8684. c = 0;
  8685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8686. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8687. {
  8688. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8689. c++;
  8690. }
  8691. sstr[c] = '\0';
  8692. minChargingRateFloat = atof(sstr);
  8693. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8694. {
  8695. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8696. }
  8697. else
  8698. {
  8699. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8700. }
  8701. }
  8702. else
  8703. {
  8704. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8705. {
  8706. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8707. }
  8708. else
  8709. {
  8710. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8711. }
  8712. }
  8713. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8714. {
  8715. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8716. if(connectorIdInt != 0)
  8717. {
  8718. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8719. goto end;
  8720. }
  8721. strcpy(filename, ChargePointMaxProfile_JSON );
  8722. fptr1 = fopen(filename, "r");
  8723. if (!fptr1)
  8724. {
  8725. //file not exist
  8726. DEBUG_INFO("Unable to open the input file!!\n");
  8727. fptr1 = fopen(filename, "w+");
  8728. }
  8729. else
  8730. {
  8731. //Check Charging Profile Count
  8732. while(fscanf(fptr1, "%s", word) != EOF)
  8733. {
  8734. //DEBUG_INFO("word=%s\n",word);
  8735. if(strstr(word, "chargingProfileId")!= NULL)
  8736. {
  8737. //DEBUG_INFO("test chargingProfileId \n");
  8738. n_chargingProfile = n_chargingProfile + 1;
  8739. //DEBUG_INFO("chargingProfileId Found\n");
  8740. }
  8741. }
  8742. }
  8743. fclose(fptr1);
  8744. }
  8745. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8746. {
  8747. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8748. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8749. {
  8750. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8751. goto end;
  8752. }
  8753. memset(filename, 0, ARRAY_SIZE(filename));
  8754. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8755. fptr1 = fopen(filename, "r");
  8756. if (!fptr1)
  8757. {
  8758. //file not exist
  8759. //DEBUG_INFO("Unable to open the input file!!\n");
  8760. fptr1 = fopen(filename, "w+");
  8761. }
  8762. else
  8763. {
  8764. //Check Charging Profile Count
  8765. while(fscanf(fptr1, "%s", word) != EOF)
  8766. {
  8767. //DEBUG_INFO("word=%s\n",word);
  8768. if(strstr(word, "chargingProfileId")!= NULL)
  8769. {
  8770. //DEBUG_INFO("test chargingProfileId \n");
  8771. n_chargingProfile = n_chargingProfile + 1;
  8772. //DEBUG_INFO("chargingProfileId Found\n");
  8773. }
  8774. }
  8775. }
  8776. fclose(fptr1);
  8777. }
  8778. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8779. {
  8780. //printf("set chargingProfile 1-4\n");
  8781. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8782. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8783. if(connectorIdInt == 0)
  8784. {
  8785. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8786. goto end;
  8787. }
  8788. int tempIndex = 0;
  8789. //check Transaction active
  8790. if(gunType[connectorIdInt -1] == 'J')
  8791. {
  8792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8793. {
  8794. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8795. }
  8796. else
  8797. {
  8798. tempIndex = connectorIdInt -1;
  8799. }
  8800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8801. {
  8802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8803. {
  8804. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8805. {
  8806. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8807. {
  8808. meet = TRUE;
  8809. break;
  8810. }
  8811. }
  8812. }
  8813. }
  8814. }
  8815. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8816. {
  8817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8818. {
  8819. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8820. }
  8821. else
  8822. {
  8823. tempIndex = connectorIdInt -1;
  8824. }
  8825. for (int index = 0; index < CCS_QUANTITY; index++)
  8826. {
  8827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8828. {
  8829. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8830. {
  8831. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8832. {
  8833. meet = TRUE;
  8834. break;
  8835. }
  8836. }
  8837. }
  8838. }
  8839. }
  8840. else if(gunType[connectorIdInt -1] == 'G')
  8841. {
  8842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8843. {
  8844. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8845. }
  8846. else
  8847. {
  8848. tempIndex = connectorIdInt -1;
  8849. }
  8850. for (int index = 0; index < GB_QUANTITY; index++)
  8851. {
  8852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8853. {
  8854. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8855. {
  8856. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8857. {
  8858. meet = TRUE;
  8859. break;
  8860. }
  8861. }
  8862. }
  8863. }
  8864. }
  8865. else
  8866. {
  8867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8868. {
  8869. tempIndex = 2;
  8870. }
  8871. else
  8872. {
  8873. tempIndex = (connectorIdInt -1);
  8874. }
  8875. for (int index = 0; index < AC_QUANTITY; index++)
  8876. {
  8877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8878. {
  8879. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8880. {
  8881. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8882. {
  8883. meet = TRUE;
  8884. break;
  8885. }
  8886. }
  8887. }
  8888. }
  8889. }
  8890. //check Transaction active
  8891. if(meet == FALSE)
  8892. {
  8893. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8894. goto end;
  8895. }
  8896. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8897. {
  8898. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8899. goto end;
  8900. }
  8901. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8902. fptr1 = fopen(filename, "r");
  8903. if (!fptr1)
  8904. {
  8905. //file not exist
  8906. DEBUG_INFO("Unable to open the input file!!\n");
  8907. fptr1 = fopen(filename, "w+");
  8908. }
  8909. else
  8910. {
  8911. //Check Charging Profile Count
  8912. while(fscanf(fptr1, "%s", word) != EOF)
  8913. {
  8914. //DEBUG_INFO("word=%s\n",word);
  8915. if(strstr(word, "chargingProfileId")!= NULL)
  8916. {
  8917. //DEBUG_INFO("test chargingProfileId \n");
  8918. n_chargingProfile = n_chargingProfile + 1;
  8919. //DEBUG_INFO("chargingProfileId Found\n");
  8920. }
  8921. }
  8922. }
  8923. fclose(fptr1);
  8924. }
  8925. // Check ChargeProfileMaxStackLevel
  8926. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8927. {
  8928. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8929. goto end;
  8930. }
  8931. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8932. {
  8933. int i = 0;
  8934. char fnametemp[200]={0};
  8935. n_chargingProfile = 0;
  8936. //Check ChargePointMaxProfile.json exit
  8937. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8938. {
  8939. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8940. //Check Charging Profile Count
  8941. while(fscanf(fptr1, "%s", word) != EOF)
  8942. {
  8943. //DEBUG_INFO("word=%s\n",word);
  8944. if(strstr(word, "chargingProfileId")!= NULL)
  8945. {
  8946. //DEBUG_INFO("test chargingProfileId \n");
  8947. n_chargingProfile = n_chargingProfile + 1;
  8948. i = i + 1;
  8949. //DEBUG_INFO("chargingProfileId Found\n");
  8950. }
  8951. memset(word, 0, ARRAY_SIZE(word));
  8952. }
  8953. fclose(fptr1);
  8954. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8955. }
  8956. //Check TxDefaultProfile_0.json exit
  8957. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8958. {
  8959. i = 0;
  8960. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8961. //Check Charging Profile Count
  8962. while(fscanf(fptr1, "%s", word) != EOF)
  8963. {
  8964. //DEBUG_INFO("word=%s\n",word);
  8965. if(strstr(word, "chargingProfileId")!= NULL)
  8966. {
  8967. //DEBUG_INFO("test chargingProfileId \n");
  8968. n_chargingProfile = n_chargingProfile + 1;
  8969. i = i + 1;
  8970. //DEBUG_INFO("chargingProfileId Found\n");
  8971. }
  8972. memset(word, 0, ARRAY_SIZE(word));
  8973. }
  8974. fclose(fptr1);
  8975. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8976. }
  8977. //Check TxDefaultProfile_%d.json
  8978. for(int j=1; j <= gunTotalNumber; j++)
  8979. {
  8980. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8981. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8982. if((access(fnametemp,F_OK))!=-1)
  8983. {
  8984. i = 0;
  8985. fptr1 = fopen(fnametemp, "r");
  8986. //Check Charging Profile Count
  8987. while(fscanf(fptr1, "%s", word) != EOF)
  8988. {
  8989. //DEBUG_INFO("word=%s\n",word);
  8990. if(strstr(word, "chargingProfileId")!= NULL)
  8991. {
  8992. //DEBUG_INFO("test chargingProfileId \n");
  8993. n_chargingProfile = n_chargingProfile + 1;
  8994. i = i + 1;
  8995. //DEBUG_INFO("chargingProfileId Found\n");
  8996. }
  8997. memset(word, 0, ARRAY_SIZE(word));
  8998. }
  8999. fclose(fptr1);
  9000. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9001. }
  9002. }
  9003. //Check TxProfile_%d.json
  9004. for(int j=1; j <= gunTotalNumber; j++)
  9005. {
  9006. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9007. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9008. if((access(fnametemp,F_OK))!=-1)
  9009. {
  9010. i = 0;
  9011. fptr1 = fopen(fnametemp, "r");
  9012. //Check Charging Profile Count
  9013. while(fscanf(fptr1, "%s", word) != EOF)
  9014. {
  9015. //DEBUG_INFO("word=%s\n",word);
  9016. if(strstr(word, "chargingProfileId")!= NULL)
  9017. {
  9018. //DEBUG_INFO("test chargingProfileId \n");
  9019. n_chargingProfile = n_chargingProfile + 1;
  9020. i = i + 1;
  9021. //DEBUG_INFO("chargingProfileId Found\n");
  9022. }
  9023. memset(word, 0, ARRAY_SIZE(word));
  9024. }
  9025. fclose(fptr1);
  9026. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9027. }
  9028. }
  9029. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9030. {
  9031. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9032. goto end;
  9033. }
  9034. }
  9035. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9036. //**********************************Write to File********************************************************/
  9037. FILE *infile;
  9038. FILE *outfile;
  9039. // open file for writing
  9040. infile = fopen (filename, "r");
  9041. outfile = fopen (tempfile, "w");
  9042. int d =0;
  9043. d = fgetc(infile);
  9044. //DEBUG_INFO("d:%d\n",d);
  9045. rewind(infile);
  9046. //*璉 瘚 辣蝏     1嚗   0 */
  9047. if(d == EOF)
  9048. {
  9049. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9050. fprintf(outfile,"%s\n",payload);
  9051. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9052. fclose(infile);
  9053. fclose(outfile);
  9054. sprintf(rmFileCmd,"rm -f %s",filename);
  9055. system(rmFileCmd);
  9056. rename(tempfile, filename);
  9057. sleep(1);
  9058. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9059. //system(rmFileCmd);
  9060. }
  9061. else
  9062. {
  9063. char buf[1000]={0};
  9064. int ChargingProfileAdded = FALSE;
  9065. while (fgets(buf, sizeof(buf), infile) != NULL)
  9066. {
  9067. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9068. //*************************tempconnectorIdInt*********************************/
  9069. loc = strstr(buf, "connectorId");
  9070. c = 0;
  9071. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9072. while (loc[strlen("connectorId")+2+c] != ',')
  9073. {
  9074. sstr[c] = loc[strlen("connectorId")+2+c];
  9075. c++;
  9076. }
  9077. sstr[c] = '\0';
  9078. tempconnectorIdInt = atoi(sstr);
  9079. //*************************tempchargingProfileIdInt*********************************/
  9080. loc = strstr(buf, "chargingProfileId");
  9081. c = 0;
  9082. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9083. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9084. {
  9085. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9086. c++;
  9087. }
  9088. sstr[c] = '\0';
  9089. tempchargingProfileIdInt = atoi(sstr);
  9090. //*************************tempstackLevelInt*********************************/
  9091. loc = strstr(buf, "stackLevel");
  9092. c = 0;
  9093. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9094. while (loc[strlen("stackLevel")+2+c] != ',')
  9095. {
  9096. sstr[c] = loc[strlen("stackLevel")+2+c];
  9097. c++;
  9098. }
  9099. sstr[c] = '\0';
  9100. tempstackLevelInt = atoi(sstr);
  9101. //*************************tempchargingProfilePurposeStr*********************************/
  9102. loc = strstr(payload, "chargingProfilePurpose");
  9103. c = 0;
  9104. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9105. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9106. {
  9107. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9108. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9109. c++;
  9110. }
  9111. sstr[c] = '\0';
  9112. strcpy(tempchargingProfilePurposeStr,sstr);
  9113. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9114. {
  9115. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9116. {
  9117. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9118. if(ChargingProfileAdded == FALSE)
  9119. {
  9120. fprintf(outfile,"%s\n",payload);
  9121. ChargingProfileAdded = TRUE;
  9122. }
  9123. }
  9124. else
  9125. {
  9126. if(tempstackLevelInt < stackLevelInt)
  9127. {
  9128. if(ChargingProfileAdded == FALSE)
  9129. {
  9130. fprintf(outfile,"%s\n",payload);
  9131. ChargingProfileAdded = TRUE;
  9132. fprintf(outfile,"%s\n",buf);
  9133. }
  9134. else
  9135. {
  9136. fprintf(outfile,"%s\n",buf);
  9137. }
  9138. }
  9139. else
  9140. {
  9141. if(ChargingProfileAdded == FALSE)
  9142. {
  9143. fprintf(outfile,"%s\n",buf);
  9144. fprintf(outfile,"%s\n",payload);
  9145. ChargingProfileAdded = TRUE;
  9146. }
  9147. else
  9148. {
  9149. fprintf(outfile,"%s\n",buf);
  9150. }
  9151. }
  9152. }
  9153. }
  9154. else
  9155. {
  9156. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9157. {
  9158. if(ChargingProfileAdded == FALSE)
  9159. {
  9160. fprintf(outfile,"%s\n",payload);
  9161. ChargingProfileAdded = TRUE;
  9162. fprintf(outfile,"%s\n",buf);
  9163. }
  9164. else
  9165. {
  9166. fprintf(outfile,"%s\n",buf);
  9167. }
  9168. }
  9169. else if(tempstackLevelInt < stackLevelInt)
  9170. {
  9171. if(ChargingProfileAdded == FALSE)
  9172. {
  9173. fprintf(outfile,"%s\n",payload);
  9174. ChargingProfileAdded = TRUE;
  9175. fprintf(outfile,"%s\n",buf);
  9176. }
  9177. else
  9178. {
  9179. fprintf(outfile,"%s\n",buf);
  9180. }
  9181. }
  9182. else
  9183. {
  9184. if(ChargingProfileAdded == FALSE)
  9185. {
  9186. fprintf(outfile,"%s\n",buf);
  9187. fprintf(outfile,"%s\n",payload);
  9188. ChargingProfileAdded = TRUE;
  9189. }
  9190. else
  9191. {
  9192. fprintf(outfile,"%s\n",buf);
  9193. }
  9194. }
  9195. }
  9196. } // end of while loop
  9197. fclose(infile);
  9198. fclose(outfile);
  9199. sprintf(rmFileCmd,"rm -f %s",filename);
  9200. system(rmFileCmd);
  9201. rename(tempfile, filename);
  9202. sleep(1);
  9203. result = TRUE;
  9204. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9205. }
  9206. end:
  9207. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9208. return result;
  9209. return result;
  9210. }
  9211. int handleTriggerMessageRequest(char *uuid, char *payload)
  9212. {
  9213. mtrace();
  9214. int result = FAIL;
  9215. int connectorIdIsNULL = FALSE;
  9216. int connectorIdInt =0;
  9217. char sstr[40]={0},sstrtemp[100]={ 0 };
  9218. char requestedMessagestr[40]={0};
  9219. char comfirmstr[20]={0};
  9220. int c = 0;
  9221. char *loc;
  9222. DEBUG_INFO("handleTriggerMessageRequest\n");
  9223. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9224. strcpy(sstrtemp, stringtrimspace(payload));
  9225. c = 0;
  9226. loc = strstr(sstrtemp, "requestedMessage");
  9227. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9228. {
  9229. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9230. c++;
  9231. }
  9232. sstr[c] = '\0';
  9233. strcpy(requestedMessagestr, sstr);
  9234. c = 0;
  9235. loc = strstr(sstrtemp, "connectorId");
  9236. if(loc == NULL)
  9237. {
  9238. connectorIdIsNULL = TRUE;
  9239. }
  9240. else
  9241. {
  9242. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9243. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9244. {
  9245. sstr[c] = loc[strlen("connectorId")+2+c];
  9246. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9247. c++;
  9248. }
  9249. sstr[c] = '\0';
  9250. connectorIdInt = atoi(sstr);
  9251. }
  9252. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9253. {
  9254. //connectorIdInt = json_object_get_int(connectorId);
  9255. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9256. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9257. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9258. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9259. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9260. }
  9261. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9262. {
  9263. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9264. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9265. return TRUE;
  9266. }
  9267. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9268. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9269. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9270. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9271. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9272. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9273. {
  9274. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9275. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9276. return TRUE;
  9277. }
  9278. else
  9279. {
  9280. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9281. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9282. }
  9283. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9284. {
  9285. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9286. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9287. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9288. {
  9289. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9290. }
  9291. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9292. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9293. }
  9294. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9295. {
  9296. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9297. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9298. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9299. }
  9300. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9301. {
  9302. sendBootNotificationRequest();
  9303. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9304. }
  9305. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9306. {
  9307. sendHeartbeatRequest(connectorIdInt);
  9308. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9309. }
  9310. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9311. {
  9312. if(connectorIdIsNULL == FALSE)
  9313. {
  9314. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9315. {
  9316. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9317. sendMeterValuesRequest(connectorIdInt -1);
  9318. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9319. }
  9320. }
  9321. else
  9322. {
  9323. for(int idx=0;idx< gunTotalNumber;idx++)
  9324. {
  9325. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9326. sendMeterValuesRequest(idx);
  9327. }
  9328. }
  9329. }
  9330. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9331. {
  9332. if(connectorIdIsNULL == FALSE)
  9333. {
  9334. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9335. {
  9336. sendStatusNotificationRequest(connectorIdInt -1);
  9337. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9338. }
  9339. }
  9340. else
  9341. {
  9342. for(int idx=0;idx< gunTotalNumber;idx++)
  9343. sendStatusNotificationRequest(idx);
  9344. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9345. }
  9346. }
  9347. return result;
  9348. }
  9349. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9350. {
  9351. mtrace();
  9352. int result = FAIL;
  9353. char sstr[6]={0},sstrtemp[50]={ 0 };
  9354. int connectorIdInt =0;
  9355. char comfirmstr[20]={0};
  9356. int c = 0;
  9357. int tempIndex = 0;
  9358. char *loc;
  9359. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9360. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9361. strcpy(sstrtemp, stringtrimspace(payload));
  9362. c = 0;
  9363. loc = strstr(sstrtemp, "connectorId");
  9364. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9365. while (loc[strlen("connectorId")+2+c] != '}')
  9366. {
  9367. sstr[c] = loc[strlen("connectorId")+2+c];
  9368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9369. c++;
  9370. }
  9371. sstr[c] = '\0';
  9372. connectorIdInt = atoi(sstr);
  9373. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9374. if(gunTotalNumber == 0)
  9375. {
  9376. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9377. goto end;
  9378. }
  9379. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9380. {
  9381. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9382. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9383. goto end;
  9384. }
  9385. else
  9386. {
  9387. //check Transaction active
  9388. if(gunType[connectorIdInt-1] == 'J')
  9389. {
  9390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9391. {
  9392. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9393. }
  9394. else
  9395. {
  9396. tempIndex = connectorIdInt -1;
  9397. }
  9398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9399. {
  9400. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9401. {
  9402. //stop Transaction
  9403. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9404. }
  9405. }
  9406. }
  9407. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9408. {
  9409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9410. {
  9411. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9412. }
  9413. else
  9414. {
  9415. tempIndex = connectorIdInt -1;
  9416. }
  9417. for (int index = 0; index < CCS_QUANTITY; index++)
  9418. {
  9419. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9420. {
  9421. //stop Transaction
  9422. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9423. }
  9424. }
  9425. }
  9426. else if(gunType[connectorIdInt-1] == 'G')
  9427. {
  9428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9429. {
  9430. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9431. }
  9432. else
  9433. {
  9434. tempIndex = connectorIdInt -1;
  9435. }
  9436. for (int index = 0; index < GB_QUANTITY; index++)
  9437. {
  9438. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9439. {
  9440. //stop Transaction
  9441. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9442. }
  9443. }
  9444. }
  9445. else
  9446. {
  9447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9448. {
  9449. tempIndex = 2;
  9450. }
  9451. else
  9452. {
  9453. tempIndex = connectorIdInt-1;
  9454. }
  9455. for (int index = 0; index < AC_QUANTITY; index++)
  9456. {
  9457. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9458. {
  9459. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9460. }
  9461. }
  9462. }
  9463. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9464. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9465. result = TRUE;
  9466. return result;
  9467. }
  9468. end:
  9469. //json_object_put(obj); --- remove temporally
  9470. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9471. return result;
  9472. }
  9473. static char UpdateFirmwarepayloadData[300]={0};
  9474. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9475. {
  9476. mtrace();
  9477. int result = FAIL;
  9478. pthread_t t;
  9479. sendUpdateFirmwareConfirmation(uuid);
  9480. memset(UpdateFirmwarepayloadData, 0, 300);
  9481. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9482. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9483. ////pthread_join(t, NULL); //
  9484. //pthread_detach(t);
  9485. //sendUpdateFirmwareConfirmation(uuid);
  9486. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9487. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9488. return result;
  9489. }
  9490. void *UpdateFirmwareProcess(void *data)
  9491. {
  9492. pthread_detach(pthread_self());
  9493. mtrace();
  9494. int retriesInt =0, retryIntervalInt=0;
  9495. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9496. int port=0;
  9497. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9498. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9499. //char comfirmstr[20];
  9500. int isSuccess = 0;
  9501. char ftpbuf[200];
  9502. char temp[100];
  9503. char * pch;
  9504. int retriesISNULL=FALSE;
  9505. int retryInterval=FALSE;
  9506. int c = 0;
  9507. //int i = 0;
  9508. char *loc;
  9509. char sstr[300]={ 0 };
  9510. char str[300]={ 0 };
  9511. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9512. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9513. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9514. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9515. //***************location **************/
  9516. loc = strstr(str, "location");
  9517. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9518. c = 0;
  9519. while (loc[3+strlen("location")+c] != '\"')
  9520. {
  9521. sstr[c] = loc[3+strlen("location")+c];
  9522. c++;
  9523. }
  9524. sstr[c] = '\0';
  9525. strcpy(locationstr, sstr);
  9526. //***************retries**************/
  9527. c = 0;
  9528. loc = strstr(str, "retries");
  9529. if(loc == NULL)
  9530. {
  9531. retriesISNULL=TRUE;
  9532. }
  9533. else
  9534. {
  9535. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9536. while (loc[strlen("retries")+2+c] != ',')
  9537. {
  9538. sstr[c] = loc[strlen("retries")+2+c];
  9539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9540. c++;
  9541. }
  9542. sstr[c] = '\0';
  9543. }
  9544. if(retriesISNULL == FALSE)
  9545. {
  9546. retriesInt = atoi(sstr);
  9547. }
  9548. //***************retrieveDate **************/
  9549. loc = strstr(str, "retrieveDate");
  9550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9551. c = 0;
  9552. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9553. {
  9554. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9555. c++;
  9556. }
  9557. sstr[c] = '\0';
  9558. strcpy(retrieveDatestr, sstr);
  9559. //***************retryInterval **************/
  9560. c = 0;
  9561. loc = strstr(str, "retryInterval");
  9562. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9563. if(loc == NULL)
  9564. {
  9565. retryInterval=TRUE;
  9566. }
  9567. else
  9568. {
  9569. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9570. {
  9571. sstr[c] = loc[strlen("retryInterval")+2+c];
  9572. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9573. c++;
  9574. }
  9575. sstr[c] = '\0';
  9576. }
  9577. if(retryInterval==FALSE)
  9578. {
  9579. retryIntervalInt = atoi(sstr);
  9580. }
  9581. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9582. memset(path, 0, ARRAY_SIZE(path));
  9583. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9584. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9585. if(strncmp(locationstr,"http", 4) == 0)
  9586. {
  9587. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9588. protocol, host, path);
  9589. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9590. // protocol, user, password, host, path);
  9591. sprintf(ftppath,"/%s", path);
  9592. //DEBUG_INFO("protocol =%s\n",protocol);
  9593. //DEBUG_INFO("host =%s\n",host);
  9594. //DEBUG_INFO("path =%s\n",path);
  9595. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9596. int ftppathlen=strlen(ftppath);
  9597. int i=1;
  9598. char filenametemp[50];
  9599. while(i < ftppathlen)
  9600. {
  9601. int len=ftppathlen-i;
  9602. if(ftppath[len]== 47) // '/' ascll code: 47
  9603. {
  9604. DEBUG_INFO("compare '/' all right\n");
  9605. break;
  9606. }
  9607. i=i+1;
  9608. }
  9609. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9610. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9611. filenametemp[i+1] = 0;
  9612. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9613. do{
  9614. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9615. sleep(retryIntervalInt);
  9616. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9617. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9618. if(!isSuccess)
  9619. {
  9620. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9621. }
  9622. else
  9623. {
  9624. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9625. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9626. //isUpdateRequest = TRUE;
  9627. }
  9628. }
  9629. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9630. {
  9631. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9632. memset(temp, 0, ARRAY_SIZE(temp));
  9633. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9634. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9635. int ftppathlen=strlen(ftpbuf);
  9636. int i=1;
  9637. char filenametemp[50];
  9638. while(i < ftppathlen)
  9639. {
  9640. int len=ftppathlen-i;
  9641. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9642. {
  9643. DEBUG_INFO(" compare '/' all right\n");
  9644. break;
  9645. }
  9646. i=i+1;
  9647. }
  9648. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9649. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9650. filenametemp[i+1] = 0;
  9651. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9652. pch=strchr(temp,'@');
  9653. if(pch==NULL)
  9654. {
  9655. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9656. protocol, host, &port, path);
  9657. strcpy(user,"anonymous");
  9658. strcpy(password,"");
  9659. }
  9660. else
  9661. {
  9662. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9663. protocol, user, password, host, &port, path);
  9664. }
  9665. sscanf(host,"%[^/]%s",host1, path1);
  9666. sprintf(ftppath,"%s", path1);
  9667. //DEBUG_INFO("protocol =%s\n",protocol);
  9668. //DEBUG_INFO("user =%s\n",user);
  9669. //DEBUG_INFO("password =%s\n",password);
  9670. //DEBUG_INFO("host1 =%s\n",host1);
  9671. //DEBUG_INFO("port =%d\n",port);
  9672. //DEBUG_INFO("path1 =%s\n",path1);
  9673. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9674. //ftpFile(host, user, password, port, ftppath, fname);
  9675. //download firmware pthred
  9676. if(port == 0)
  9677. {
  9678. port = 21;
  9679. }
  9680. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9681. do{
  9682. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9683. sleep(retryIntervalInt);
  9684. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9685. if(!isSuccess)
  9686. {
  9687. //BulldogUtil.sleepMs(interval*1000);
  9688. DEBUG_INFO("Update firmware request and download file fail.\n");
  9689. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9690. }
  9691. else
  9692. {
  9693. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9694. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9695. //isUpdateRequest = TRUE;
  9696. }
  9697. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9698. }
  9699. else
  9700. {
  9701. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9702. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9703. }
  9704. pthread_exit(NULL);
  9705. }
  9706. //==========================================
  9707. // Handle server response routine
  9708. //==========================================
  9709. void handleAuthorizeResponse(char *payload, int gun_index)
  9710. {
  9711. mtrace();
  9712. char expiryDatestr[30]={0};
  9713. char parentIdTagstr[20]={0};
  9714. char statusstr[20]={0};
  9715. char expiryDatestrtemp[30]={0};
  9716. char parentIdTagstrtemp[20]={0};
  9717. char IdTagstrtemp[20]={0};
  9718. char statusstrtemp[20]={0};
  9719. int expiryDateISNULL=FALSE;
  9720. int parentIdTagISNULL=FALSE;
  9721. char sstr[160]={0};
  9722. char* filename = AuthorizationCache_JSON;
  9723. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9724. char *loc;
  9725. int resultRename=0;
  9726. int responseIdTagInfoAsZero= 0;
  9727. char rmFileCmd[50]={0};
  9728. DEBUG_INFO("handleAuthorizeResponse...\n");
  9729. json_object *Authorize;
  9730. Authorize = json_tokener_parse(payload);
  9731. if(!is_error(Authorize))
  9732. {
  9733. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9734. {
  9735. // Required data
  9736. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9737. // Optional data
  9738. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9739. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9740. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9741. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9742. }
  9743. }
  9744. json_object_put(Authorize);
  9745. if(expiryDateISNULL == FALSE)
  9746. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9747. if(parentIdTagISNULL == FALSE)
  9748. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9749. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9750. //Update idTag information to authorization cache if supproted
  9751. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9752. {
  9753. if((access(filename,F_OK))!=-1)
  9754. {
  9755. printf("AuthorizationCache exist.\n");
  9756. }
  9757. else
  9758. {
  9759. printf("AuthorizationCache not exist\n");
  9760. FILE *log = fopen(filename, "w+");
  9761. if(log == NULL)
  9762. {
  9763. printf("log is NULL\n");
  9764. goto out;
  9765. }
  9766. else
  9767. {
  9768. fclose(log);
  9769. }
  9770. }
  9771. FILE *infile;
  9772. FILE *outfile;
  9773. // open file for writing
  9774. infile = fopen (filename, "r");
  9775. outfile = fopen (tempfile, "w");
  9776. int c;
  9777. c = fgetc(infile);
  9778. //DEBUG_INFO("c:%d\n",c);
  9779. rewind(infile);
  9780. if(c == EOF)
  9781. {
  9782. DEBUG_INFO("Orignal File is NULL\n");
  9783. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9784. {
  9785. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9786. }
  9787. else
  9788. {
  9789. strcpy(expiryDatestrtemp, "");
  9790. }
  9791. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9792. {
  9793. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9794. }
  9795. else
  9796. {
  9797. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9798. }
  9799. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9800. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9801. fclose(infile);
  9802. fclose(outfile);
  9803. sprintf(rmFileCmd,"rm -f %s",filename);
  9804. system(rmFileCmd);
  9805. resultRename = rename(tempfile, filename);
  9806. if(resultRename == 0)
  9807. {
  9808. printf("File renamed successfully");
  9809. }
  9810. else
  9811. {
  9812. printf("Error: unable to rename the file");
  9813. }
  9814. }
  9815. else
  9816. {
  9817. char buf[160]={0};
  9818. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9819. {
  9820. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9821. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9822. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9823. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9824. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9825. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9826. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9827. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9828. //------------------IdTag-----------------------
  9829. loc = strstr(buf, "idTag");
  9830. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9831. c = 0;
  9832. while (loc[3+strlen("idTag")+c] != '\"')
  9833. {
  9834. sstr[c] = loc[3+strlen("idTag")+c];
  9835. c++;
  9836. }
  9837. sstr[c] = '\0';
  9838. strcpy(IdTagstrtemp,sstr);
  9839. //*********************expiryDate***************/
  9840. loc = strstr(buf, "expiryDate");
  9841. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9842. c = 0;
  9843. while (loc[3+strlen("expiryDate")+c] != '\"')
  9844. {
  9845. sstr[c] = loc[3+strlen("expiryDate")+c];
  9846. c++;
  9847. }
  9848. sstr[c] = '\0';
  9849. strcpy(expiryDatestr,sstr);
  9850. //*********************parentIdTag***************/
  9851. loc = strstr(buf, "parentIdTag");
  9852. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9853. c = 0;
  9854. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9855. {
  9856. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9857. c++;
  9858. }
  9859. sstr[c] = '\0';
  9860. strcpy(parentIdTagstr,sstr);
  9861. //*********************status***************/
  9862. loc = strstr(buf, "status");
  9863. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9864. c = 0;
  9865. while (loc[3+strlen("status")+c] != '\"')
  9866. {
  9867. sstr[c] = loc[3+strlen("status")+c];
  9868. c++;
  9869. }
  9870. sstr[c] = '\0';
  9871. strcpy(statusstr,sstr);
  9872. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9873. {
  9874. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9875. responseIdTagInfoAsZero = 1;
  9876. }
  9877. else
  9878. {
  9879. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9880. }
  9881. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9882. {
  9883. //modify item
  9884. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9885. {
  9886. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9887. }
  9888. else
  9889. {
  9890. strcpy(expiryDatestrtemp, "");
  9891. }
  9892. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9893. {
  9894. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9895. }
  9896. else
  9897. {
  9898. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9899. }
  9900. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9901. }
  9902. else
  9903. {
  9904. //wrie original item
  9905. strcpy(expiryDatestrtemp, expiryDatestr);
  9906. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9907. strcpy(statusstrtemp, statusstr);
  9908. }
  9909. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9910. }
  9911. fclose(infile);
  9912. fclose(outfile);
  9913. sprintf(rmFileCmd,"rm -f %s",filename);
  9914. system(rmFileCmd);
  9915. resultRename = rename(tempfile, filename);
  9916. if(resultRename == 0)
  9917. {
  9918. DEBUG_INFO("File renamed successfully");
  9919. }
  9920. else
  9921. {
  9922. DEBUG_INFO("Error: unable to rename the file");
  9923. }
  9924. }
  9925. }
  9926. out:
  9927. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9928. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9929. authorizeRetryTimes = 0;
  9930. }
  9931. char * strtrimc( char * s )
  9932. {
  9933. char * p1 = s;
  9934. char * p2 = s;
  9935. while(*p1 != '\0')
  9936. {
  9937. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9938. {
  9939. if(*p1 != ',')
  9940. {
  9941. p1 ++;
  9942. }
  9943. else
  9944. {
  9945. break;
  9946. }
  9947. }
  9948. if(*p1 != ',')
  9949. {
  9950. * p2 ++ = *p1 ++;
  9951. //printf("p2=%s\n",p2);
  9952. }
  9953. else
  9954. {
  9955. break;
  9956. }
  9957. }
  9958. *p2 = '\0';
  9959. return (s);
  9960. }
  9961. void handleBootNotificationResponse(char *payload, int gun_index)
  9962. {
  9963. mtrace();
  9964. char statusStr[12]={0};
  9965. char currentTimeStr[30]={0};
  9966. int intervalInt = 0;
  9967. struct tm tp;
  9968. char buf[28]={0};
  9969. char timebuf[50]={0};
  9970. DEBUG_INFO("handleBootNotificationResponse...\n");
  9971. json_object *BootNotification;
  9972. BootNotification = json_tokener_parse(payload);
  9973. if(!is_error(BootNotification))
  9974. {
  9975. // Required data
  9976. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9977. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9978. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9979. }
  9980. json_object_put(BootNotification);
  9981. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9982. BootNotificationInterval = intervalInt;
  9983. HeartBeatWaitTime = intervalInt;
  9984. //write back to ShmOCPP16Data->BootNotification
  9985. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9986. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9987. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9988. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9989. {
  9990. server_sign = TRUE;
  9991. server_pending =FALSE;
  9992. }
  9993. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9994. {
  9995. server_pending = TRUE;
  9996. }
  9997. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9998. tp.tm_isdst = -1;
  9999. //time_t utc = mktime(&tp);
  10000. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10001. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10002. sprintf(timebuf,"date -s '%s'",buf);
  10003. system(timebuf);
  10004. srand(time(NULL));
  10005. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10006. //==============================================
  10007. // RTC sync
  10008. //==============================================
  10009. system("/sbin/hwclock -w --systohc");
  10010. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10011. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10012. }
  10013. void handleDataTransferResponse(char *payload, int gun_index)
  10014. {
  10015. char sstr[160]={0};//sstr[200]={ 0 };
  10016. int c = 0;
  10017. char *loc;
  10018. DEBUG_INFO("handleDataTransferResponse ...\n");
  10019. loc = strstr(payload, "status");
  10020. printf("loc=%s\n",loc);
  10021. c = 0;
  10022. while (loc[3+strlen("status")+c] != '\"')
  10023. {
  10024. sstr[c] = loc[3+strlen("status")+c];
  10025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10026. c++;
  10027. }
  10028. sstr[c] = '\0';
  10029. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10030. }
  10031. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10032. {
  10033. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10034. //struct json_object *obj;
  10035. // obj = json_tokener_parse(payload);
  10036. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10037. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10038. //No fields are defined.
  10039. }
  10040. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10041. {
  10042. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10043. //struct json_object *obj;
  10044. // obj = json_tokener_parse(payload);
  10045. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10046. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10047. //No fields are defined.
  10048. }
  10049. void handleHeartbeatResponse(char *payload, int gun_index)
  10050. {
  10051. mtrace();
  10052. struct tm tp;
  10053. char buf[28]={0};
  10054. char timebuf[50]={0};
  10055. DEBUG_INFO("handleHeartbeatResponse...\n");
  10056. json_object *Heartbeat;
  10057. Heartbeat = json_tokener_parse(payload);
  10058. if(!is_error(Heartbeat))
  10059. {
  10060. // Required data
  10061. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10062. }
  10063. json_object_put(BootNotification);
  10064. if(FirstHeartBeat == 0)
  10065. {
  10066. FirstHeartBeat = 1;
  10067. DEBUG_INFO("FirstHeartBeat \n");
  10068. }
  10069. HeartBeatWithNOResponse = 0;
  10070. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10071. tp.tm_isdst = -1;
  10072. //time_t utc = mktime(&tp);
  10073. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10074. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10075. sprintf(timebuf,"date -s '%s'",buf);
  10076. system(timebuf);
  10077. //==============================================
  10078. // RTC sync
  10079. //==============================================
  10080. system("/sbin/hwclock -w --systohc");
  10081. //===============================================
  10082. //Print Out HeartBeat log
  10083. //===============================================
  10084. {
  10085. double diff_t;
  10086. struct tm tp,tp1;
  10087. // BootNotification Receive Time
  10088. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10089. tp.tm_isdst = -1;
  10090. time_t BootNotificationReceiveTime = mktime(&tp);
  10091. //HeartBeat Receive Time
  10092. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10093. tp1.tm_isdst = -1;
  10094. time_t HeartBeatReceiveTime = mktime(&tp1);
  10095. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10096. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10097. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10098. {
  10099. HeartBeatCountPerHour = (int)diff_t / 3600;
  10100. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10101. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10102. }
  10103. }
  10104. }
  10105. void handleMeterValuesResponse(char *payload, int gun_index)
  10106. {
  10107. mtrace();
  10108. DEBUG_INFO("handleMeterValuesResponse...\n");
  10109. }
  10110. void handleStartTransactionResponse(char *payload, int gun_index)
  10111. {
  10112. mtrace();
  10113. //int transactionIdInt = 0;
  10114. FILE *outfile;
  10115. char data[100]={0};
  10116. DEBUG_INFO("handleStartTransactionResponse...\n");
  10117. json_object *StartTransaction;
  10118. StartTransaction = json_tokener_parse(payload);
  10119. if(!is_error(StartTransaction))
  10120. {
  10121. // Required data
  10122. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10123. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10124. // Optional data
  10125. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10126. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10127. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10128. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10129. }
  10130. json_object_put(StartTransaction);
  10131. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10132. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10133. //-----------Start : write to the Queue TransactionId file -----------------//
  10134. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10135. {}
  10136. else
  10137. {
  10138. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10139. if(log == NULL)
  10140. {
  10141. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10142. return ;
  10143. }
  10144. else
  10145. {
  10146. fclose(log);
  10147. }
  10148. }
  10149. // open file for writing
  10150. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10151. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10152. {
  10153. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10154. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10155. fputs(data, outfile);
  10156. fclose (outfile);
  10157. }
  10158. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10159. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10160. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10161. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10162. }
  10163. void handleStatusNotificationResponse(char *payload, int gun_index)
  10164. {
  10165. mtrace();
  10166. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10167. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10168. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10169. }
  10170. void handleStopTransactionnResponse(char *payload, int gun_index)
  10171. {
  10172. mtrace();
  10173. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10174. json_object *StopTransaction;
  10175. StopTransaction = json_tokener_parse(payload);
  10176. if(!is_error(StopTransaction))
  10177. {
  10178. // Optional data
  10179. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10180. {
  10181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10182. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10184. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10186. }
  10187. }
  10188. json_object_put(StopTransaction);
  10189. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10190. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10191. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10192. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10193. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10194. }
  10195. //==========================================
  10196. // Handle Error routine
  10197. //==========================================
  10198. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10199. {
  10200. mtrace();
  10201. #ifdef SystemLogMessage
  10202. DEBUG_INFO("errorCode: %s\n", errorCode);
  10203. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10204. DEBUG_INFO("errorDetails: %s\n", payload);
  10205. #endif
  10206. }
  10207. //===============================================
  10208. // Common routine
  10209. //===============================================
  10210. int initialConfigurationTable(void)
  10211. {
  10212. //clock_t start_t, end_t, total_t;
  10213. FILE *fp;
  10214. FILE *outfile;
  10215. char str[200]={0};
  10216. char sstr[100]={0};
  10217. int c = 0;
  10218. char *loc;
  10219. DEBUG_INFO("initialConfigurationTable...\n");
  10220. //start_t = clock();
  10221. //printf("Starting of the program, start_t = %ld\n", start_t);
  10222. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10223. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10224. {
  10225. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10226. if(outfile == NULL)
  10227. {
  10228. DEBUG_INFO("Error opening file\n");
  10229. return FALSE;
  10230. }
  10231. /*Core Profile*/
  10232. //AllowOfflineTxForUnknownId
  10233. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10234. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10238. //AuthorizationCacheEnabled
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10243. //AuthorizeRemoteTxRequests
  10244. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10248. //BlinkRepeat
  10249. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10253. //ClockAlignedDataInterval
  10254. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10258. //ConnectionTimeOut
  10259. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10263. //GetConfigurationMaxKeys
  10264. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10268. // HeartbeatInterval
  10269. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10273. // LightIntensity
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10278. // LocalAuthorizeOffline
  10279. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10283. // LocalPreAuthorize
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10288. // MaxEnergyOnInvalidId
  10289. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10292. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10294. // MeterValuesAlignedData
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10299. // MeterValuesAlignedDataMaxLength
  10300. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "6");
  10304. // MeterValuesSampledData
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10308. 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");
  10309. // MeterValuesSampledDataMaxLength
  10310. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10314. // MeterValueSampleInterval
  10315. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10319. // MinimumStatusDuration
  10320. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10323. server_cycle_Status = 120; //StatusNotification cycle
  10324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10325. // NumberOfConnectors
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10329. {
  10330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10331. }
  10332. else
  10333. {
  10334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10335. }
  10336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10337. // ResetRetries
  10338. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10342. // ConnectorPhaseRotation
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10347. // ConnectorPhaseRotationMaxLength
  10348. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10352. // StopTransactionOnEVSideDisconnect
  10353. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10357. // StopTransactionOnInvalidId
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10362. // StopTxnAlignedData
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10367. // StopTxnAlignedDataMaxLength
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10372. // StopTxnSampledData
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10377. // StopTxnSampledDataMaxLength
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10381. {
  10382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10383. }
  10384. else
  10385. {
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10387. }
  10388. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10390. // SupportedFeatureProfiles
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10395. // SupportedFeatureProfilesMaxLength
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10400. // TransactionMessageAttempts
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10404. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10406. // TransactionMessageRetryInterval
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10410. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10412. // UnlockConnectorOnEVSideDisconnect
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10417. // WebSocketPingInterval
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10422. //* Local Auth List Management Profile*/
  10423. #if 0
  10424. //For OCTT Test Case
  10425. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10428. #endif
  10429. #if 1
  10430. //LocalAuthListEnabled
  10431. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10435. #endif
  10436. //LocalAuthListMaxLength
  10437. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10441. //SendLocalListMaxLength
  10442. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "50");
  10446. //ReserveConnectorZeroSupported
  10447. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10451. //* Smart Charging Profile */
  10452. //ChargeProfileMaxStackLevel
  10453. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10457. // ChargingScheduleAllowedChargingRateUnit
  10458. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10462. // ChargingScheduleMaxPeriods
  10463. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10467. // ConnectorSwitch3to1PhaseSupported
  10468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10472. // MaxChargingProfilesInstalled
  10473. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10477. fclose(outfile);
  10478. }
  10479. else
  10480. {
  10481. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10482. char keystr[60]={0};
  10483. char readonlystr[10]={0};
  10484. char valuestr[100]={0};
  10485. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10486. if(fp == NULL) {
  10487. DEBUG_INFO("Error opening file");
  10488. return FALSE;
  10489. }
  10490. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10491. {
  10492. //DEBUG_INFO("Get Configuration \n");
  10493. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10494. //*************************key*********************************/
  10495. loc = strstr(str, "key");
  10496. c = 0;
  10497. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10498. while (loc[strlen("key")+3+c] != '\"')
  10499. {
  10500. sstr[c] = loc[strlen("key")+3+c];
  10501. c++;
  10502. }
  10503. sstr[c] = '\0';
  10504. strcpy(keystr,sstr);
  10505. //*************************readonly*********************************/
  10506. loc = strstr(str, "readonly");
  10507. c = 0;
  10508. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10509. while (loc[strlen("readonly")+2+c] != ',')
  10510. {
  10511. sstr[c] = loc[strlen("readonly")+2+c];
  10512. c++;
  10513. }
  10514. sstr[c] = '\0';
  10515. strcpy(readonlystr,sstr);
  10516. //*************************value*********************************/
  10517. loc = strstr(str, "value");
  10518. c = 0;
  10519. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10520. while (loc[strlen("value")+3+c] != '\"')
  10521. {
  10522. sstr[c] = loc[strlen("value")+3+c];
  10523. c++;
  10524. }
  10525. sstr[c] = '\0';
  10526. strcpy(valuestr,sstr);
  10527. // DEBUG_INFO("keystr=%s\n",keystr);
  10528. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10529. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10530. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10531. {
  10532. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10533. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10535. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10536. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10537. }
  10538. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10539. {
  10540. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10543. }
  10544. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10548. }
  10549. if(strcmp(keystr, "BlinkRepeat") == 0)
  10550. {
  10551. //Charger.BlinkRepeat = Integer.parseInt(value);
  10552. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10554. }
  10555. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10556. {
  10557. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10559. }
  10560. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10561. {
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10564. }
  10565. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10566. {
  10567. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10569. }
  10570. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10571. {
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10574. HeartBeatWaitTime = atoi(valuestr);
  10575. }
  10576. if(strcmp(keystr, "LightIntensity") == 0)
  10577. {
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10580. }
  10581. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10582. {
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10585. }
  10586. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10587. {
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10590. }
  10591. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10592. {
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10595. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10596. }
  10597. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10598. {
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10601. }
  10602. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10603. {
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10606. }
  10607. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10611. }
  10612. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10613. {
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10616. }
  10617. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10618. {
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10621. }
  10622. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10623. {
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10626. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10627. }
  10628. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10629. {
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10632. }
  10633. if(strcmp(keystr, "ResetRetries") == 0)
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10637. }
  10638. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10639. {
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10642. }
  10643. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10644. {
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10647. }
  10648. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10649. {
  10650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10652. }
  10653. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10654. {
  10655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10657. }
  10658. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10659. {
  10660. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10662. }
  10663. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10664. {
  10665. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10667. }
  10668. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10669. {
  10670. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10672. }
  10673. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10674. {
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10677. }
  10678. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10679. {
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10682. }
  10683. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10684. {
  10685. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10687. }
  10688. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10689. {
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10692. TransactionMessageAttemptsValue = atoi(valuestr);
  10693. }
  10694. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10695. {
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10698. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10699. }
  10700. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10701. {
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10704. }
  10705. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10706. {
  10707. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10709. }
  10710. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10711. {
  10712. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10714. }
  10715. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10716. {
  10717. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10719. }
  10720. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10721. {
  10722. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10724. }
  10725. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10726. {
  10727. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10729. }
  10730. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10731. {
  10732. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10734. }
  10735. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10736. {
  10737. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10739. }
  10740. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10741. {
  10742. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10744. }
  10745. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10746. {
  10747. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10749. }
  10750. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10751. {
  10752. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10754. }
  10755. }
  10756. fclose(fp);
  10757. }
  10758. return 0;
  10759. }
  10760. void StoreConfigurationTable(void)
  10761. {
  10762. FILE *outfile;
  10763. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10764. if(outfile == NULL)
  10765. {
  10766. DEBUG_INFO("Error opening file");
  10767. return ;
  10768. }
  10769. /*Core Profile*/
  10770. //AllowOfflineTxForUnknownId
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10773. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10776. */
  10777. //DEBUG_INFO("data=%s\n",data);
  10778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10779. //AuthorizationCacheEnabled
  10780. /*
  10781. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10784. */
  10785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10786. //AuthorizeRemoteTxRequests
  10787. /*
  10788. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10791. */
  10792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10793. //BlinkRepeat
  10794. /*
  10795. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10798. */
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10800. //ClockAlignedDataInterval
  10801. /*
  10802. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10805. */
  10806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10807. //ConnectionTimeOut
  10808. /*
  10809. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10812. */
  10813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10814. //GetConfigurationMaxKeys
  10815. /*
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10819. */
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10821. // HeartbeatInterval
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10828. // LightIntensity
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10835. // LocalAuthorizeOffline
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10842. // LocalPreAuthorize
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10849. // MaxEnergyOnInvalidId
  10850. /*
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10854. */
  10855. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10857. // MeterValuesAlignedData
  10858. /*
  10859. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10862. */
  10863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10864. // MeterValuesAlignedDataMaxLength
  10865. /*
  10866. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10869. */
  10870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10871. // MeterValuesSampledData
  10872. /*
  10873. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10876. */
  10877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10878. // MeterValuesSampledDataMaxLength
  10879. /*
  10880. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10883. */
  10884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10885. // MeterValueSampleInterval
  10886. /*
  10887. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10890. */
  10891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10892. // MinimumStatusDuration
  10893. /*
  10894. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10897. */
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10899. // NumberOfConnectors
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10904. {
  10905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10906. }
  10907. else
  10908. {
  10909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10910. }
  10911. */
  10912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10913. // ResetRetries
  10914. /*
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10918. */
  10919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10920. // ConnectorPhaseRotation
  10921. /*
  10922. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10925. */
  10926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10927. // ConnectorPhaseRotationMaxLength
  10928. /*
  10929. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10932. */
  10933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10934. // StopTransactionOnEVSideDisconnect
  10935. /*
  10936. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10939. */
  10940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10941. // StopTransactionOnInvalidId
  10942. /*
  10943. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10946. */
  10947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10948. // StopTxnAlignedData
  10949. /*
  10950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10953. */
  10954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10955. // StopTxnAlignedDataMaxLength
  10956. /*
  10957. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10960. */
  10961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10962. // StopTxnSampledData
  10963. /*
  10964. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10967. */
  10968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10969. // StopTxnSampledDataMaxLength
  10970. /*
  10971. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10974. */
  10975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10976. // SupportedFeatureProfiles
  10977. /*
  10978. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10981. */
  10982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10983. // SupportedFeatureProfilesMaxLength
  10984. /*
  10985. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10988. */
  10989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10990. // TransactionMessageAttempts
  10991. /*
  10992. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10995. */
  10996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10997. // TransactionMessageRetryInterval
  10998. /*
  10999. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11002. */
  11003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11004. // UnlockConnectorOnEVSideDisconnect
  11005. /*
  11006. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11009. */
  11010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11011. // WebSocketPingInterval
  11012. /*
  11013. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11016. */
  11017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11018. //* Local Auth List Management Profile*/
  11019. //LocalAuthListEnabled
  11020. /*
  11021. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11024. */
  11025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11026. //LocalAuthListMaxLength
  11027. /*
  11028. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11031. */
  11032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11033. //SendLocalListMaxLength
  11034. /*
  11035. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11038. */
  11039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11040. //ReserveConnectorZeroSupported
  11041. /*
  11042. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11045. */
  11046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11047. //* Smart Charging Profile */
  11048. //ChargeProfileMaxStackLevel
  11049. /*
  11050. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11053. */
  11054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11055. // ChargingScheduleAllowedChargingRateUnit
  11056. /*
  11057. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11060. */
  11061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11062. // ChargingScheduleMaxPeriods
  11063. /*
  11064. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11067. */
  11068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11069. // ConnectorSwitch3to1PhaseSupported
  11070. /*
  11071. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11074. */
  11075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11076. // MaxChargingProfilesInstalled
  11077. /*
  11078. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11081. */
  11082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11083. fclose(outfile);
  11084. }
  11085. void getKeyValue(char *keyReq)
  11086. {
  11087. int isEmpty = FALSE;
  11088. int isKnowKey = FALSE;
  11089. DEBUG_INFO("keyReq = %s\n", keyReq);
  11090. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11091. isEmpty = TRUE;
  11092. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11099. }
  11100. else
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11103. }
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11105. isKnowKey = TRUE;
  11106. }
  11107. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11114. }
  11115. else
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11118. }
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11120. isKnowKey = TRUE;
  11121. }
  11122. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11129. }
  11130. else
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11133. }
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11135. isKnowKey = TRUE;
  11136. }
  11137. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11144. }
  11145. else
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11148. }
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11150. isKnowKey = TRUE;
  11151. }
  11152. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11159. }
  11160. else
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11163. }
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11165. isKnowKey = TRUE;
  11166. }
  11167. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11225. isKnowKey = TRUE;
  11226. }
  11227. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11234. }
  11235. else
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11238. }
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11240. isKnowKey = TRUE;
  11241. }
  11242. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11249. }
  11250. else
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11253. }
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11255. isKnowKey = TRUE;
  11256. }
  11257. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11264. }
  11265. else
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11268. }
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11270. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11271. isKnowKey = TRUE;
  11272. }
  11273. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11280. }
  11281. else
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11284. }
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11286. isKnowKey = TRUE;
  11287. }
  11288. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11295. }
  11296. else
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11299. }
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11301. isKnowKey = TRUE;
  11302. }
  11303. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11310. }
  11311. else
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11314. }
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11316. isKnowKey = TRUE;
  11317. }
  11318. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11325. }
  11326. else
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11329. }
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11331. isKnowKey = TRUE;
  11332. }
  11333. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11340. }
  11341. else
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11344. }
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11346. isKnowKey = TRUE;
  11347. }
  11348. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11355. }
  11356. else
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11359. }
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11361. isKnowKey = TRUE;
  11362. }
  11363. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11370. }
  11371. else
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11374. }
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11376. isKnowKey = TRUE;
  11377. }
  11378. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11385. }
  11386. else
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11389. }
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11391. isKnowKey = TRUE;
  11392. }
  11393. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11400. }
  11401. else
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11404. }
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11406. isKnowKey = TRUE;
  11407. }
  11408. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11415. }
  11416. else
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11419. }
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11421. isKnowKey = TRUE;
  11422. }
  11423. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11430. }
  11431. else
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11434. }
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11436. isKnowKey = TRUE;
  11437. }
  11438. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11445. }
  11446. else
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11449. }
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11451. isKnowKey = TRUE;
  11452. }
  11453. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11460. }
  11461. else
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11464. }
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11466. isKnowKey = TRUE;
  11467. }
  11468. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11475. }
  11476. else
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11479. }
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11481. isKnowKey = TRUE;
  11482. }
  11483. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11490. }
  11491. else
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11494. }
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11580. }
  11581. else
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11584. }
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11586. isKnowKey = TRUE;
  11587. }
  11588. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11595. }
  11596. else
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11599. }
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11601. isKnowKey = TRUE;
  11602. }
  11603. #if 1
  11604. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11608. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11611. }
  11612. else
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11615. }
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11617. isKnowKey = TRUE;
  11618. }
  11619. #endif
  11620. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11624. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11625. {
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11627. }
  11628. else
  11629. {
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11631. }
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11633. isKnowKey = TRUE;
  11634. }
  11635. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11639. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11640. {
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11642. }
  11643. else
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11646. }
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11648. isKnowKey = TRUE;
  11649. }
  11650. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11654. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11657. }
  11658. else
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11661. }
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11663. isKnowKey = TRUE;
  11664. }
  11665. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11666. {
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11669. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11670. {
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11672. }
  11673. else
  11674. {
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11676. }
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11678. isKnowKey = TRUE;
  11679. }
  11680. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11681. {
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11684. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11685. {
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11687. }
  11688. else
  11689. {
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11691. }
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11693. isKnowKey = TRUE;
  11694. }
  11695. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11696. {
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11699. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11700. {
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11702. }
  11703. else
  11704. {
  11705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11706. }
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11708. isKnowKey = TRUE;
  11709. }
  11710. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11711. {
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11714. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11715. {
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11717. }
  11718. else
  11719. {
  11720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11721. }
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11723. isKnowKey = TRUE;
  11724. }
  11725. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11726. {
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11729. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11730. {
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11732. }
  11733. else
  11734. {
  11735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11736. }
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11738. isKnowKey = TRUE;
  11739. }
  11740. //=========================================================
  11741. if(!isEmpty && !isKnowKey)
  11742. {
  11743. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11744. strcpy(unknownkey[UnknownKeynum], keyReq);
  11745. UnknownKeynum = UnknownKeynum + 1;
  11746. }
  11747. }
  11748. void processUnkownKey(void)
  11749. {
  11750. DEBUG_INFO("processUnkownKey...\n");
  11751. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11752. for(int index=0; index < UnknownKeynum; index++)
  11753. {
  11754. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11755. {
  11756. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11757. }
  11758. }
  11759. }
  11760. int setKeyValue(char *key, char *value)
  11761. {
  11762. int isSuccess = NotSupported;
  11763. int check_ascii=0;
  11764. char str[10]={0};
  11765. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11766. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11767. {
  11768. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11770. {
  11771. strcpy(str, (const char*)value);
  11772. for(int i = 0; str[i]; i++){
  11773. str[i] = tolower(str[i]);
  11774. }
  11775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11776. isSuccess = ConfigurationStatus_Accepted;
  11777. }
  11778. else
  11779. {
  11780. isSuccess = ConfigurationStatus_Rejected;
  11781. }
  11782. }
  11783. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11784. {
  11785. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11787. {
  11788. strcpy(str, (const char*)value);
  11789. for(int i = 0; str[i]; i++){
  11790. str[i] = tolower(str[i]);
  11791. }
  11792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11793. isSuccess = ConfigurationStatus_Accepted;
  11794. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11795. }
  11796. else
  11797. {
  11798. isSuccess = ConfigurationStatus_Rejected;
  11799. }
  11800. }
  11801. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11802. {
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11804. {
  11805. strcpy(str, (const char*)value);
  11806. for(int i = 0; str[i]; i++)
  11807. {
  11808. str[i] = tolower(str[i]);
  11809. }
  11810. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11812. isSuccess = ConfigurationStatus_Accepted;
  11813. }
  11814. else
  11815. {
  11816. isSuccess = ConfigurationStatus_Rejected;
  11817. }
  11818. }
  11819. if(strcmp(key, "BlinkRepeat") == 0)
  11820. {
  11821. //Charger.BlinkRepeat = Integer.parseInt(value);
  11822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11823. {
  11824. check_ascii = value[0];
  11825. if( (check_ascii < 48) || (check_ascii > 57) )
  11826. {
  11827. isSuccess = ConfigurationStatus_Rejected;
  11828. }
  11829. else
  11830. {
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. }
  11834. }
  11835. else
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. }
  11840. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11841. {
  11842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11843. {
  11844. check_ascii = value[0];
  11845. if( (check_ascii < 48) || (check_ascii > 57) )
  11846. {
  11847. isSuccess = ConfigurationStatus_Rejected;
  11848. }
  11849. else
  11850. {
  11851. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11853. isSuccess = ConfigurationStatus_Accepted;
  11854. }
  11855. }
  11856. else
  11857. {
  11858. isSuccess = ConfigurationStatus_Rejected;
  11859. }
  11860. }
  11861. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11862. {
  11863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11864. {
  11865. check_ascii = value[0];
  11866. if( (check_ascii < 48) || (check_ascii > 57) )
  11867. {
  11868. isSuccess = ConfigurationStatus_Rejected;
  11869. }
  11870. else
  11871. {
  11872. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11885. {
  11886. check_ascii = value[0];
  11887. if( (check_ascii < 48) || (check_ascii > 57) )
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. else
  11892. {
  11893. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11895. isSuccess = ConfigurationStatus_Accepted;
  11896. }
  11897. }
  11898. else
  11899. {
  11900. isSuccess = ConfigurationStatus_Rejected;
  11901. }
  11902. }
  11903. if(strcmp(key, "HeartbeatInterval") == 0)
  11904. {
  11905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11906. {
  11907. check_ascii = value[0];
  11908. if( (check_ascii < 48) || (check_ascii > 57) )
  11909. {
  11910. isSuccess = ConfigurationStatus_Rejected;
  11911. }
  11912. else
  11913. {
  11914. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11916. HeartBeatWaitTime = atoi(value);
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "LightIntensity") == 0)
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11928. {
  11929. check_ascii = value[0];
  11930. if( (check_ascii < 48) || (check_ascii > 57) )
  11931. {
  11932. isSuccess = ConfigurationStatus_Rejected;
  11933. }
  11934. else
  11935. {
  11936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11937. isSuccess = ConfigurationStatus_Accepted;
  11938. }
  11939. }
  11940. else
  11941. {
  11942. isSuccess = ConfigurationStatus_Rejected;
  11943. }
  11944. }
  11945. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11946. {
  11947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11948. {
  11949. strcpy(str, (const char*)value);
  11950. for(int i = 0; str[i]; i++)
  11951. {
  11952. str[i] = tolower(str[i]);
  11953. }
  11954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11955. isSuccess = ConfigurationStatus_Accepted;
  11956. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11957. }
  11958. else
  11959. {
  11960. isSuccess = ConfigurationStatus_Rejected;
  11961. }
  11962. }
  11963. if(strcmp(key, "LocalPreAuthorize") == 0)
  11964. {
  11965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11966. {
  11967. strcpy(str, (const char*)value);
  11968. for(int i = 0; str[i]; i++)
  11969. {
  11970. str[i] = tolower(str[i]);
  11971. }
  11972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11973. isSuccess = ConfigurationStatus_Accepted;
  11974. }
  11975. else
  11976. {
  11977. isSuccess = ConfigurationStatus_Rejected;
  11978. }
  11979. }
  11980. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11981. {
  11982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11983. {
  11984. check_ascii = value[0];
  11985. if( (check_ascii < 48) || (check_ascii > 57) )
  11986. {
  11987. isSuccess = ConfigurationStatus_Rejected;
  11988. }
  11989. else
  11990. {
  11991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11992. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11993. isSuccess = ConfigurationStatus_Accepted;
  11994. }
  11995. }
  11996. else
  11997. {
  11998. isSuccess = ConfigurationStatus_Rejected;
  11999. }
  12000. }
  12001. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12002. {
  12003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12004. {
  12005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12006. isSuccess = ConfigurationStatus_Accepted;
  12007. }
  12008. else
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. }
  12013. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12014. {
  12015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12016. {
  12017. check_ascii = value[0];
  12018. if( (check_ascii < 48) || (check_ascii > 57) )
  12019. {
  12020. isSuccess = ConfigurationStatus_Rejected;
  12021. }
  12022. else
  12023. {
  12024. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12026. isSuccess = ConfigurationStatus_Accepted;
  12027. }
  12028. }
  12029. else
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. }
  12034. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12035. {
  12036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12037. {
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. else
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. }
  12046. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12047. {
  12048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12049. {
  12050. check_ascii = value[0];
  12051. if( (check_ascii < 48) || (check_ascii > 57) )
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. else
  12056. {
  12057. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12059. isSuccess = ConfigurationStatus_Accepted;
  12060. }
  12061. }
  12062. else
  12063. {
  12064. isSuccess = ConfigurationStatus_Rejected;
  12065. }
  12066. }
  12067. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12068. {
  12069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12070. {
  12071. check_ascii = value[0];
  12072. if( (check_ascii < 48) || (check_ascii > 57) )
  12073. {
  12074. isSuccess = ConfigurationStatus_Rejected;
  12075. }
  12076. else
  12077. {
  12078. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. if(strcmp(key, "MinimumStatusDuration") == 0)
  12089. {
  12090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12091. {
  12092. check_ascii = value[0];
  12093. if( (check_ascii < 48) || (check_ascii > 57) )
  12094. {
  12095. isSuccess = ConfigurationStatus_Rejected;
  12096. }
  12097. else
  12098. {
  12099. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12100. {
  12101. isSuccess = ConfigurationStatus_Rejected;
  12102. }
  12103. else
  12104. {
  12105. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12107. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12108. isSuccess = ConfigurationStatus_Accepted;
  12109. }
  12110. }
  12111. }
  12112. else
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. }
  12117. if(strcmp(key, "NumberOfConnectors") == 0)
  12118. {
  12119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12120. {
  12121. check_ascii = value[0];
  12122. if( (check_ascii < 48) || (check_ascii > 57) )
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. else
  12127. {
  12128. //Charger.ResetRetries = Integer.parseInt(value);
  12129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12130. isSuccess = ConfigurationStatus_Accepted;
  12131. }
  12132. }
  12133. else
  12134. {
  12135. isSuccess = ConfigurationStatus_Rejected;
  12136. }
  12137. }
  12138. if(strcmp(key, "ResetRetries") == 0)
  12139. {
  12140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12141. {
  12142. check_ascii = value[0];
  12143. if( (check_ascii < 48) || (check_ascii > 57) )
  12144. {
  12145. isSuccess = ConfigurationStatus_Rejected;
  12146. }
  12147. else
  12148. {
  12149. //Charger.ResetRetries = Integer.parseInt(value);
  12150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12151. isSuccess = ConfigurationStatus_Accepted;
  12152. }
  12153. }
  12154. else
  12155. {
  12156. isSuccess = ConfigurationStatus_Rejected;
  12157. }
  12158. }
  12159. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12160. {
  12161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12162. {
  12163. strcpy(str, (const char*)value);
  12164. for(int i = 0; str[i]; i++)
  12165. {
  12166. str[i] = tolower(str[i]);
  12167. }
  12168. if(strcmp(str, "notapplicable")== 0)
  12169. {
  12170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12171. isSuccess = ConfigurationStatus_Accepted;
  12172. }
  12173. else if(strcmp(str, "unknown")== 0)
  12174. {
  12175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. else if(strcmp(str, "rst")== 0)
  12179. {
  12180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. else if(strcmp(str, "rts")== 0)
  12184. {
  12185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12186. isSuccess = ConfigurationStatus_Accepted;
  12187. }
  12188. else if(strcmp(str, "srt")== 0)
  12189. {
  12190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12191. isSuccess = ConfigurationStatus_Accepted;
  12192. }
  12193. else if(strcmp(str, "str")== 0)
  12194. {
  12195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12196. isSuccess = ConfigurationStatus_Accepted;
  12197. }
  12198. else if(strcmp(str, "trs")== 0)
  12199. {
  12200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12201. isSuccess = ConfigurationStatus_Accepted;
  12202. }
  12203. else if(strcmp(str, "tsr")== 0)
  12204. {
  12205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12206. isSuccess = ConfigurationStatus_Accepted;
  12207. }
  12208. else
  12209. {
  12210. isSuccess = ConfigurationStatus_Rejected;
  12211. }
  12212. }
  12213. else
  12214. {
  12215. isSuccess = ConfigurationStatus_Rejected;
  12216. }
  12217. }
  12218. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12219. {
  12220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12221. {
  12222. check_ascii = value[0];
  12223. if( (check_ascii < 48) || (check_ascii > 57) )
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. else
  12228. {
  12229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12230. isSuccess = ConfigurationStatus_Accepted;
  12231. }
  12232. }
  12233. else
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. }
  12238. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12239. {
  12240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12241. {
  12242. strcpy(str, (const char*)value);
  12243. for(int i = 0; str[i]; i++)
  12244. {
  12245. str[i] = tolower(str[i]);
  12246. }
  12247. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12249. isSuccess = ConfigurationStatus_Accepted;
  12250. }
  12251. else
  12252. {
  12253. isSuccess = ConfigurationStatus_Rejected;
  12254. }
  12255. }
  12256. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12257. {
  12258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12259. {
  12260. strcpy(str, (const char*)value);
  12261. for(int i = 0; str[i]; i++)
  12262. {
  12263. str[i] = tolower(str[i]);
  12264. }
  12265. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12267. isSuccess = ConfigurationStatus_Accepted;
  12268. }
  12269. else
  12270. {
  12271. isSuccess = ConfigurationStatus_Rejected;
  12272. }
  12273. }
  12274. if(strcmp(key, "StopTxnAlignedData") == 0)
  12275. {
  12276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12277. {
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12279. isSuccess = ConfigurationStatus_Accepted;
  12280. }
  12281. else
  12282. {
  12283. isSuccess = ConfigurationStatus_Rejected;
  12284. }
  12285. }
  12286. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12287. {
  12288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12289. {
  12290. check_ascii = value[0];
  12291. if( (check_ascii < 48) || (check_ascii > 57) )
  12292. {
  12293. isSuccess = ConfigurationStatus_Rejected;
  12294. }
  12295. else
  12296. {
  12297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12298. isSuccess = ConfigurationStatus_Accepted;
  12299. }
  12300. }
  12301. else
  12302. {
  12303. isSuccess = ConfigurationStatus_Rejected;
  12304. }
  12305. }
  12306. if(strcmp(key, "StopTxnSampledData") == 0)
  12307. {
  12308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12309. {
  12310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12311. isSuccess = ConfigurationStatus_Accepted;
  12312. }
  12313. else
  12314. {
  12315. isSuccess = ConfigurationStatus_Rejected;
  12316. }
  12317. }
  12318. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12319. {
  12320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12321. {
  12322. check_ascii = value[0];
  12323. if( (check_ascii < 48) || (check_ascii > 57) )
  12324. {
  12325. isSuccess = ConfigurationStatus_Rejected;
  12326. }
  12327. else
  12328. {
  12329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12330. isSuccess = ConfigurationStatus_Accepted;
  12331. }
  12332. }
  12333. else
  12334. {
  12335. isSuccess = ConfigurationStatus_Rejected;
  12336. }
  12337. }
  12338. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12339. {
  12340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12341. {
  12342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12343. isSuccess = ConfigurationStatus_Accepted;
  12344. }
  12345. else
  12346. {
  12347. isSuccess = ConfigurationStatus_Rejected;
  12348. }
  12349. }
  12350. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12351. {
  12352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12353. {
  12354. check_ascii = value[0];
  12355. if( (check_ascii < 48) || (check_ascii > 57) )
  12356. {
  12357. isSuccess = ConfigurationStatus_Rejected;
  12358. }
  12359. else
  12360. {
  12361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12362. isSuccess = ConfigurationStatus_Accepted;
  12363. }
  12364. }
  12365. else
  12366. {
  12367. isSuccess = ConfigurationStatus_Rejected;
  12368. }
  12369. }
  12370. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12371. {
  12372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12373. {
  12374. check_ascii = value[0];
  12375. if( (check_ascii < 48) || (check_ascii > 57) )
  12376. {
  12377. isSuccess = ConfigurationStatus_Rejected;
  12378. }
  12379. else
  12380. {
  12381. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12383. TransactionMessageAttemptsValue = atoi(value);
  12384. isSuccess = ConfigurationStatus_Accepted;
  12385. }
  12386. }
  12387. else
  12388. {
  12389. isSuccess = ConfigurationStatus_Rejected;
  12390. }
  12391. }
  12392. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12393. {
  12394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12395. {
  12396. check_ascii = value[0];
  12397. if( (check_ascii < 48) || (check_ascii > 57) )
  12398. {
  12399. isSuccess = ConfigurationStatus_Rejected;
  12400. }
  12401. else
  12402. {
  12403. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12405. TransactionMessageRetryIntervalValue = atoi(value);
  12406. isSuccess = ConfigurationStatus_Accepted;
  12407. }
  12408. }
  12409. else
  12410. {
  12411. isSuccess = ConfigurationStatus_Rejected;
  12412. }
  12413. }
  12414. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12415. {
  12416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12417. {
  12418. strcpy(str, (const char*)value);
  12419. for(int i = 0; str[i]; i++)
  12420. {
  12421. str[i] = tolower(str[i]);
  12422. }
  12423. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12425. isSuccess = ConfigurationStatus_Accepted;
  12426. }
  12427. else
  12428. {
  12429. isSuccess = ConfigurationStatus_Rejected;
  12430. }
  12431. }
  12432. if(strcmp(key, "WebSocketPingInterval") == 0)
  12433. {
  12434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12435. {
  12436. check_ascii = value[0];
  12437. if( (check_ascii < 48) || (check_ascii > 57) )
  12438. {
  12439. isSuccess = ConfigurationStatus_Rejected;
  12440. }
  12441. else
  12442. {
  12443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12444. isSuccess = ConfigurationStatus_Accepted;
  12445. }
  12446. }
  12447. else
  12448. {
  12449. isSuccess = ConfigurationStatus_Rejected;
  12450. }
  12451. }
  12452. #if 0
  12453. //For OCPP Test Case
  12454. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12455. {
  12456. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12457. {
  12458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12459. isSuccess = ConfigurationStatus_Accepted;
  12460. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12461. }
  12462. else
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. }
  12467. #endif
  12468. #if 1
  12469. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12470. {
  12471. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12472. {
  12473. strcpy(str, (const char*)value);
  12474. for(int i = 0; str[i]; i++)
  12475. {
  12476. str[i] = tolower(str[i]);
  12477. }
  12478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12479. isSuccess = ConfigurationStatus_Accepted;
  12480. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12481. }
  12482. else
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. }
  12487. #endif
  12488. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12489. {
  12490. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12491. {
  12492. check_ascii = value[0];
  12493. if( (check_ascii < 48) || (check_ascii > 57) )
  12494. {
  12495. isSuccess = ConfigurationStatus_Rejected;
  12496. }
  12497. else
  12498. {
  12499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12500. isSuccess = ConfigurationStatus_Accepted;
  12501. }
  12502. }
  12503. else
  12504. {
  12505. isSuccess = ConfigurationStatus_Rejected;
  12506. }
  12507. }
  12508. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12509. {
  12510. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12511. {
  12512. check_ascii = value[0];
  12513. if( (check_ascii < 48) || (check_ascii > 57) )
  12514. {
  12515. isSuccess = ConfigurationStatus_Rejected;
  12516. }
  12517. else
  12518. {
  12519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12520. isSuccess = ConfigurationStatus_Accepted;
  12521. }
  12522. }
  12523. else
  12524. {
  12525. isSuccess = ConfigurationStatus_Rejected;
  12526. }
  12527. }
  12528. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12529. {
  12530. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12531. {
  12532. strcpy(str, (const char*)value);
  12533. for(int i = 0; str[i]; i++)
  12534. {
  12535. str[i] = tolower(str[i]);
  12536. }
  12537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12538. isSuccess = ConfigurationStatus_Accepted;
  12539. }
  12540. else
  12541. {
  12542. isSuccess = ConfigurationStatus_Rejected;
  12543. }
  12544. }
  12545. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12546. {
  12547. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12548. {
  12549. check_ascii = value[0];
  12550. if( (check_ascii < 48) || (check_ascii > 57) )
  12551. {
  12552. isSuccess = ConfigurationStatus_Rejected;
  12553. }
  12554. else
  12555. {
  12556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12557. isSuccess = ConfigurationStatus_Accepted;
  12558. }
  12559. }
  12560. else
  12561. {
  12562. isSuccess = ConfigurationStatus_Rejected;
  12563. }
  12564. }
  12565. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12566. {
  12567. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12568. {
  12569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12570. isSuccess = ConfigurationStatus_Accepted;
  12571. }
  12572. else
  12573. {
  12574. isSuccess = ConfigurationStatus_Rejected;
  12575. }
  12576. }
  12577. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12578. {
  12579. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12580. {
  12581. check_ascii = value[0];
  12582. if( (check_ascii < 48) || (check_ascii > 57) )
  12583. {
  12584. isSuccess = ConfigurationStatus_Rejected;
  12585. }
  12586. else
  12587. {
  12588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12589. isSuccess = ConfigurationStatus_Accepted;
  12590. }
  12591. }
  12592. else
  12593. {
  12594. isSuccess = ConfigurationStatus_Rejected;
  12595. }
  12596. }
  12597. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12598. {
  12599. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12600. {
  12601. strcpy(str, (const char*)value);
  12602. for(int i = 0; str[i]; i++)
  12603. {
  12604. str[i] = tolower(str[i]);
  12605. }
  12606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12607. isSuccess = ConfigurationStatus_Accepted;
  12608. }
  12609. else
  12610. {
  12611. isSuccess = ConfigurationStatus_Rejected;
  12612. }
  12613. }
  12614. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12615. {
  12616. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12617. {
  12618. check_ascii = value[0];
  12619. if( (check_ascii < 48) || (check_ascii > 57) )
  12620. {
  12621. isSuccess = ConfigurationStatus_Rejected;
  12622. }
  12623. else
  12624. {
  12625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12626. isSuccess = ConfigurationStatus_Accepted;
  12627. }
  12628. }
  12629. else
  12630. {
  12631. isSuccess = ConfigurationStatus_Rejected;
  12632. }
  12633. }
  12634. return isSuccess;
  12635. }
  12636. int TransactionMessageAttemptsGet(void)
  12637. {
  12638. return TransactionMessageAttemptsValue;
  12639. }
  12640. int FirstHeartBeatResponse(void)
  12641. {
  12642. return FirstHeartBeat;
  12643. }
  12644. int TransactionMessageRetryIntervalGet(void)
  12645. {
  12646. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12647. }
  12648. int ReadHttpStatus(int sock)
  12649. {
  12650. //char c;
  12651. char buff[1024]="",*ptr=buff+1;
  12652. int bytes_received, status;
  12653. DEBUG_INFO("Begin Response ..\n");
  12654. while((bytes_received = recv(sock, ptr, 1, 0))){
  12655. if(bytes_received==-1){
  12656. perror("ReadHttpStatus");
  12657. exit(1);
  12658. }
  12659. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12660. ptr++;
  12661. }
  12662. *ptr=0;
  12663. ptr=buff+1;
  12664. sscanf(ptr,"%*s %d ", &status);
  12665. DEBUG_INFO("%s\n",ptr);
  12666. DEBUG_INFO("status=%d\n",status);
  12667. DEBUG_INFO("End Response ..\n");
  12668. return (bytes_received>0)?status:0;
  12669. }
  12670. //the only filed that it parsed is 'Content-Length'
  12671. int ParseHeader(int sock)
  12672. {
  12673. //char c;
  12674. char buff[1024]="",*ptr=buff+4;
  12675. int bytes_received;
  12676. DEBUG_INFO("Begin HEADER ..\n");
  12677. while((bytes_received = recv(sock, ptr, 1, 0))){
  12678. if(bytes_received==-1){
  12679. perror("Parse Header");
  12680. exit(1);
  12681. }
  12682. if(
  12683. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12684. (ptr[-1]=='\r') && (*ptr=='\n' )
  12685. ) break;
  12686. ptr++;
  12687. }
  12688. *ptr=0;
  12689. ptr=buff+4;
  12690. //printf("%s",ptr);
  12691. if(bytes_received){
  12692. ptr=strstr(ptr,"Content-Length:");
  12693. if(ptr){
  12694. sscanf(ptr,"%*s %d",&bytes_received);
  12695. }else
  12696. bytes_received=-1; //unknown size
  12697. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12698. }
  12699. DEBUG_INFO("End HEADER ..\n");
  12700. return bytes_received ;
  12701. }
  12702. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12703. {
  12704. char rmFileCmd[100]={0};
  12705. char FilePath[100]={0};
  12706. char ftpbuf[200];
  12707. int systemresult;
  12708. //DEBUG_INFO("filename=%s\n",filename);
  12709. //DEBUG_INFO("url=%s\n",url);
  12710. sprintf(FilePath,"/mnt/%s",filename);
  12711. if((access(FilePath,F_OK))!=-1)
  12712. {
  12713. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12714. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12715. system(rmFileCmd);
  12716. }
  12717. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12718. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12719. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12720. systemresult = system(ftpbuf);
  12721. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12722. if(systemresult != 0)
  12723. {
  12724. DEBUG_INFO("http DownLoad error!\n");
  12725. return FALSE;
  12726. }
  12727. return TRUE;
  12728. }
  12729. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12730. {
  12731. char rmFileCmd[100]={0};
  12732. char FilePath[100]={0};
  12733. char ftpbuf[200];
  12734. int systemresult;
  12735. //char temp[100];
  12736. sprintf(FilePath,"/mnt/%s",filename);
  12737. if((access(FilePath,F_OK))!=-1)
  12738. {
  12739. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12740. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12741. system(rmFileCmd);
  12742. }
  12743. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12744. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12745. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12746. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12747. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12748. systemresult = system(ftpbuf);
  12749. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12750. if(systemresult != 0)
  12751. {
  12752. printf("wget error!\n");
  12753. return FALSE;
  12754. }
  12755. return TRUE;
  12756. }
  12757. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12758. {
  12759. char rmFileCmd[100]={0};
  12760. char FilePath[100]={0};
  12761. char ftpbuf[200];
  12762. int systemresult;
  12763. //DEBUG_INFO("filename=%s\n",filename);
  12764. //DEBUG_INFO("url=%s\n",url);
  12765. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12766. if((access(FilePath,F_OK))!=-1)
  12767. {
  12768. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12769. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12770. system(rmFileCmd);
  12771. }
  12772. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12773. if(fp == NULL)
  12774. {
  12775. DEBUG_INFO("log is NULL\n");
  12776. return FALSE;
  12777. }
  12778. else
  12779. {
  12780. fprintf(fp, "%s\n", url);
  12781. fprintf(fp, "%s\n", filename);
  12782. fclose(fp);
  12783. }
  12784. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12785. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12786. systemresult = system(ftpbuf);
  12787. DEBUG_INFO("systemresult = %d\n",systemresult);
  12788. if(systemresult != 0)
  12789. {
  12790. DEBUG_INFO("http upload error!\n");
  12791. return FALSE;
  12792. }
  12793. return TRUE;
  12794. }
  12795. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12796. {
  12797. struct hostent* server;
  12798. char *IPbuffer;
  12799. char ftpbuf[200];
  12800. int systemresult;
  12801. // To retrieve host information
  12802. server = gethostbyname(location);
  12803. // To convert an Internet network
  12804. // address into ASCII string
  12805. IPbuffer = inet_ntoa(*((struct in_addr*)
  12806. server->h_addr_list[0]));
  12807. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12808. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12809. /* format : ftpput -u username -p passwd IP target source*/
  12810. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12811. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12812. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12813. systemresult = system(ftpbuf);
  12814. DEBUG_INFO("systemresult=%d\n",systemresult);
  12815. if(systemresult != 0)
  12816. {
  12817. DEBUG_INFO("ftpput error!\n");
  12818. return FALSE;
  12819. }
  12820. return TRUE;
  12821. }
  12822. /**
  12823. * Place the contents of the specified file into a memory buffer
  12824. *
  12825. * @param[in] filename The path and name of the file to read
  12826. * @param[out] filebuffer A pointer to the contents in memory
  12827. * @return status 0 success, 1 on failure
  12828. */
  12829. int get_file_contents(const char* filename, char** outbuffer) {
  12830. FILE* file = NULL;
  12831. long filesize;
  12832. const int blocksize = 1;
  12833. size_t readsize;
  12834. char* filebuffer;
  12835. // Open the file
  12836. file = fopen(filename, "r");
  12837. if (NULL == file)
  12838. {
  12839. printf("'%s' not opened\n", filename);
  12840. exit(EXIT_FAILURE);
  12841. }
  12842. // Determine the file size
  12843. fseek(file, 0, SEEK_END);
  12844. filesize = ftell(file);
  12845. rewind (file);
  12846. // Allocate memory for the file contents
  12847. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12848. *outbuffer = filebuffer;
  12849. if (filebuffer == NULL)
  12850. {
  12851. fputs ("malloc out-of-memory", stderr);
  12852. exit(EXIT_FAILURE);
  12853. }
  12854. // Read in the file
  12855. readsize = fread(filebuffer, blocksize, filesize, file);
  12856. if (readsize != filesize)
  12857. {
  12858. fputs ("didn't read file completely",stderr);
  12859. exit(EXIT_FAILURE);
  12860. }
  12861. // Clean exit
  12862. fclose(file);
  12863. return EXIT_SUCCESS;
  12864. }
  12865. static int selectSqlCount = 0;
  12866. static int callback(void *data, int argc, char **argv, char **azColName){
  12867. int i;
  12868. //printf("%s: ", (const char*)data);
  12869. selectSqlCount = argc;
  12870. for(i = 0; i<argc; i++){
  12871. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12872. }
  12873. //printf("\n");
  12874. return 0;
  12875. }
  12876. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12877. //int i;
  12878. //printf("%s:\n", (const char*)data);
  12879. localversion = argv[5] ? atoi(argv[5]) : 0;
  12880. //printf("localversion=%d\n", localversion);
  12881. return 0;
  12882. }
  12883. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12884. //int i;
  12885. //printf("%s:\n", (const char*)data);
  12886. //idTag
  12887. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12888. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12889. //parentIdTag
  12890. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12891. //expir_date
  12892. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12893. //status
  12894. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12895. //version
  12896. idTagQuery.listVersionInt = atoi(argv[5]);
  12897. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12898. return 0;
  12899. }
  12900. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12901. {
  12902. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12903. // printf("localversion=%d\n", localversion);
  12904. return 0;
  12905. }
  12906. //=========================================
  12907. // Sqlite3 related function
  12908. //=========================================
  12909. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12910. {
  12911. for (int i = 0; i < n_columns; i++)
  12912. {
  12913. DEBUG_INFO("%s/t", col_values[i]);
  12914. }
  12915. DEBUG_INFO("/n");
  12916. return 0;
  12917. }
  12918. void OCPP_getListVerion()
  12919. {
  12920. int rc = 0;
  12921. // const char* data = "Callback function called";
  12922. char sql[100];
  12923. char zErrMsg[100];
  12924. memset(sql, 0, 100);
  12925. memset(zErrMsg, 0, 100);
  12926. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12927. /* Execute SQL statement */
  12928. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12929. if( rc != SQLITE_OK )
  12930. {
  12931. DEBUG_INFO("SQL error: %s", zErrMsg);
  12932. }
  12933. }
  12934. void OCPP_getIdTag(char idTag[])
  12935. {
  12936. int rc = 0;
  12937. // const char* data = "Callback function called";
  12938. char sql[100];
  12939. char zErrMsg[100];
  12940. memset(sql, 0, 100);
  12941. memset(zErrMsg, 0, 100);
  12942. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12943. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12944. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12945. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12946. /* Execute SQL statement */
  12947. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12948. if( rc != SQLITE_OK )
  12949. {
  12950. DEBUG_INFO("SQL error: %s", zErrMsg);
  12951. }
  12952. //return ver;
  12953. }
  12954. void OCPP_get_TableAuthlocalAllData(void)
  12955. {
  12956. int rc = 0;
  12957. char sql[100];
  12958. char zErrMsg[100];
  12959. memset(sql, 0, 100);
  12960. memset(zErrMsg, 0, 100);
  12961. sprintf(sql,"select * from ocpp_auth_local ");
  12962. /* Execute SQL statement */
  12963. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12964. if( rc != SQLITE_OK )
  12965. {
  12966. DEBUG_INFO("SQL error: %s", zErrMsg);
  12967. }
  12968. //return ver;
  12969. }
  12970. int OCPP_cleanLocalList()
  12971. {
  12972. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12973. char *errMsg = 0;
  12974. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12975. if (SQLITE_OK != rc)
  12976. {
  12977. DEBUG_INFO("%s\n",errMsg);
  12978. return FALSE;
  12979. }
  12980. return TRUE;
  12981. }
  12982. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12983. {
  12984. int isSuccess = FALSE;
  12985. int ret = 0;
  12986. //const char* data = "Callback function called";
  12987. char sql[300];
  12988. char zErrMsg[200];
  12989. memset(sql, 0, 300);
  12990. memset(zErrMsg, 0, 200);
  12991. 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);
  12992. //* Execute SQL statement */
  12993. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12994. if( ret != SQLITE_OK )
  12995. {
  12996. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12997. return isSuccess;
  12998. }
  12999. memset(sql, 0, 300);
  13000. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13001. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13002. if( ret != SQLITE_OK )
  13003. {
  13004. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13005. return isSuccess;
  13006. }
  13007. isSuccess = TRUE;
  13008. return isSuccess;
  13009. }
  13010. void OCPP_deleteIdTag(char idTag[])
  13011. {
  13012. //int ver = 0;
  13013. //int isSuccess = FALSE;
  13014. int rc = 0;
  13015. char sql[100];
  13016. char zErrMsg[100];
  13017. memset(sql, 0, 100);
  13018. memset(zErrMsg, 0, 100);
  13019. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13020. //* Execute SQL statement */
  13021. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13022. if( rc != SQLITE_OK )
  13023. {
  13024. DEBUG_INFO("SQL error: %s", zErrMsg);
  13025. }
  13026. }
  13027. int GetOcppServerURL()
  13028. {
  13029. int result = FALSE;
  13030. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13031. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13032. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13033. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13034. {
  13035. #if 1
  13036. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13037. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13038. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13039. #endif
  13040. result = TRUE;
  13041. goto End;
  13042. }
  13043. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13044. {
  13045. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13046. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13047. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13048. result = TRUE;
  13049. goto End;
  13050. }
  13051. else
  13052. {
  13053. strcpy(OcppHost,"");
  13054. }
  13055. End:
  13056. return result;
  13057. }
  13058. int GetOcppPath()
  13059. {
  13060. int result = FALSE;
  13061. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13062. {
  13063. if(OcppTempPath == NULL)
  13064. {
  13065. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13066. }
  13067. else
  13068. {
  13069. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13070. }
  13071. result = TRUE;
  13072. goto End;
  13073. }
  13074. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13075. {
  13076. if(OcppTempPath == NULL)
  13077. {
  13078. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13079. }
  13080. else
  13081. {
  13082. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13083. }
  13084. result = TRUE;
  13085. goto End;
  13086. }
  13087. else
  13088. {
  13089. strcpy(OcppPath,"");
  13090. }
  13091. End:
  13092. return result;
  13093. }
  13094. int GetOcppPort()
  13095. {
  13096. return OcppPort;
  13097. }
  13098. int GetOcppConnStatus(void)
  13099. {
  13100. return ShmOCPP16Data->OcppConnStatus;
  13101. }
  13102. void SetOcppConnStatus(uint8_t status)
  13103. {
  13104. ShmOCPP16Data->OcppConnStatus = status;
  13105. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13106. }
  13107. int GetHeartBeatWithNOResponse(void)
  13108. {
  13109. return HeartBeatWithNOResponse;
  13110. }
  13111. void SetHeartBeatWithNOResponse(void)
  13112. {
  13113. HeartBeatWithNOResponse = 0;
  13114. }
  13115. void GetStartTransactionIdTag(int gun_index)
  13116. {
  13117. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13118. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13119. }
  13120. int GetTransactionId(int gunindex, unsigned char idTag[])
  13121. {
  13122. char ch;
  13123. FILE *fptr1;
  13124. int temptransactionId;
  13125. char str[100]={0};
  13126. temptransactionId = 0;
  13127. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13128. {
  13129. DEBUG_INFO("IdTag is empty.\n");
  13130. return temptransactionId;
  13131. }
  13132. /*------ Read the file ----------------*/
  13133. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13134. if (!fptr1)
  13135. {
  13136. DEBUG_INFO("QueueTransactionId file open error.\n");
  13137. //printf(" File not found or unable to open the input file!!\n");
  13138. return temptransactionId;
  13139. }
  13140. ch=fgetc(fptr1);
  13141. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13142. rewind(fptr1);
  13143. if(ch!=EOF)
  13144. {
  13145. // printf("%c",ch);
  13146. while (fgets(str, 100, fptr1) != NULL)
  13147. {
  13148. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13149. if(str[0]=='\0')
  13150. {
  13151. break;
  13152. }
  13153. char *revbuf[8] = {0}; //存放分割後的子字串
  13154. int num = 0;//分割後子字串的個數
  13155. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13156. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13157. {
  13158. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13159. {
  13160. temptransactionId = atoi(revbuf[2]);
  13161. break;
  13162. }
  13163. }
  13164. }
  13165. }
  13166. fclose(fptr1);
  13167. /*------- End of reading ---------------*/
  13168. return temptransactionId;
  13169. }
  13170. void SetTransactionIdZero(int transactionId)
  13171. {
  13172. char ch;
  13173. FILE *fptr1, *fptr2;
  13174. int temptransactionId = 0;
  13175. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13176. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13177. if (!fptr1)
  13178. {
  13179. //printf(" File not found or unable to open the input file!!\n");
  13180. return ;
  13181. }
  13182. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13183. if (!fptr2)
  13184. {
  13185. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13186. fclose(fptr1);
  13187. return ;
  13188. }
  13189. ch=fgetc(fptr1);
  13190. rewind(fptr1);
  13191. if(ch!=EOF)
  13192. {
  13193. // copy all contents to the temporary file except the specific line
  13194. while (fgets(str, 100, fptr1) != NULL)
  13195. {
  13196. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13197. if(str[0]=='\0')
  13198. {
  13199. break;
  13200. }
  13201. char *revbuf[8] = {0};
  13202. int num = 0;
  13203. strcpy(strtemp, str);
  13204. splitstring(str,",",revbuf,&num);
  13205. if(revbuf[2][0] != '\0')
  13206. {
  13207. temptransactionId = atoi(revbuf[2]);
  13208. if(transactionId != temptransactionId)
  13209. {
  13210. fprintf(fptr2, "%s\n", strtemp);
  13211. }
  13212. }
  13213. }
  13214. }
  13215. fclose(fptr1);
  13216. fclose(fptr2);
  13217. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13218. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13219. /*------ Read the file ----------------*/
  13220. }
  13221. int InternetDisconnect(void)
  13222. {
  13223. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13224. }
  13225. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13226. void storeTempStopTransaction(int gun_index)
  13227. {
  13228. char guid[37]={0};
  13229. int tempIndex = 0;
  13230. DEBUG_INFO("storeTempStopTransaction...\n");
  13231. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13232. //ENERGY_ACTIVE_IMPORT_REGISTER
  13233. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13234. if(gunType[gun_index] == 'J')
  13235. {
  13236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13237. {
  13238. tempIndex = ((gun_index==2) ? 1: 0);
  13239. }
  13240. else
  13241. {
  13242. tempIndex = gun_index;
  13243. }
  13244. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13245. {
  13246. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13247. {
  13248. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13249. }
  13250. }// END OF CHAdeMO_QUANTITY
  13251. }
  13252. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13253. {
  13254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13255. {
  13256. tempIndex = ((gun_index==2) ? 1: 0);
  13257. }
  13258. else
  13259. {
  13260. tempIndex = gun_index;
  13261. }
  13262. for (int index = 0; index < CCS_QUANTITY; index++)
  13263. {
  13264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13265. {
  13266. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13267. }
  13268. }// END OF CCS_QUANTITY
  13269. }
  13270. else if(gunType[gun_index] == 'G')
  13271. {
  13272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13273. {
  13274. tempIndex = ((gun_index==2) ? 1: 0);
  13275. }
  13276. else
  13277. {
  13278. tempIndex = gun_index;
  13279. }
  13280. for (int index = 0; index < GB_QUANTITY; index++)
  13281. {
  13282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13283. {
  13284. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13285. }
  13286. }// END OF GB_QUANTITY
  13287. }
  13288. else
  13289. {
  13290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13291. {
  13292. tempIndex = 2;
  13293. }
  13294. else
  13295. {
  13296. tempIndex = gun_index;
  13297. }
  13298. for (int index = 0; index < AC_QUANTITY; index++)
  13299. {
  13300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13301. {
  13302. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13303. }
  13304. }// END OF AC_QUANTITY
  13305. }
  13306. //Stop Transaction Time
  13307. struct timeval tmnow;
  13308. struct tm *tm;
  13309. char buf[28];//, usec_buf[6];
  13310. gettimeofday(&tmnow, NULL);
  13311. time_t t;
  13312. t = time(NULL);
  13313. /*UTC time and date*/
  13314. tm = gmtime(&t);
  13315. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13317. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13319. random_uuid(guid);
  13320. /***********************************transactionData******************************************************/
  13321. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13323. //=================================
  13324. //1. Transaction_Begin
  13325. //=================================
  13326. // Energy.Active.Export.Interval
  13327. //idx_sample=0;
  13328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13331. 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*/]);
  13332. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13333. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13334. {
  13335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13336. }
  13337. else
  13338. {
  13339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13340. }
  13341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13343. //=================================
  13344. //2. Transaction_End
  13345. //=================================
  13346. //2.1 Current.Export
  13347. //idx_sample=1;
  13348. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13349. if(gunType[gun_index] == 'J')
  13350. {
  13351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13352. {
  13353. tempIndex = ((gun_index==2) ? 1: 0);
  13354. }
  13355. else
  13356. {
  13357. tempIndex = gun_index;
  13358. }
  13359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13360. {
  13361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13362. {
  13363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13364. }
  13365. }// End of for CHAdeMO_QUANTITY
  13366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13367. }
  13368. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13369. {
  13370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13371. {
  13372. tempIndex = ((gun_index==2) ? 1: 0);
  13373. }
  13374. else
  13375. {
  13376. tempIndex = gun_index;
  13377. }
  13378. for (int index = 0; index < CCS_QUANTITY; index++)
  13379. {
  13380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13381. {
  13382. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13383. }
  13384. }// End of for CCS_QUANTITY
  13385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13386. }
  13387. else if(gunType[gun_index] == 'G')
  13388. {
  13389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13390. {
  13391. tempIndex = ((gun_index==2) ? 1: 0);
  13392. }
  13393. else
  13394. {
  13395. tempIndex = gun_index;
  13396. }
  13397. for (int index = 0; index < GB_QUANTITY; index++)
  13398. {
  13399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13400. {
  13401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13402. }
  13403. }// End of for GB_QUANTITY
  13404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13405. }
  13406. else
  13407. {
  13408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13409. {
  13410. tempIndex = 2;
  13411. }
  13412. else
  13413. {
  13414. tempIndex = gun_index;
  13415. }
  13416. for (int index = 0; index < AC_QUANTITY; index++)
  13417. {
  13418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13419. {
  13420. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13421. }
  13422. }// End of for AC_QUANTITY
  13423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13424. }
  13425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13428. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13431. //2.2 Energy.Active.Export.Interval
  13432. //idx_sample=2;
  13433. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13434. if(gunType[gun_index] == 'J')
  13435. {
  13436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13437. {
  13438. tempIndex = ((gun_index==2) ? 1: 0);
  13439. }
  13440. else
  13441. {
  13442. tempIndex = gun_index;
  13443. }
  13444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13445. {
  13446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13447. {
  13448. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13449. }
  13450. }// END OF CHAdeMO_QUANTITY
  13451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13452. }
  13453. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13454. {
  13455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13456. {
  13457. tempIndex = ((gun_index==2) ? 1: 0);
  13458. }
  13459. else
  13460. {
  13461. tempIndex = gun_index;
  13462. }
  13463. for (int index = 0; index < CCS_QUANTITY; index++)
  13464. {
  13465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13466. {
  13467. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13468. }
  13469. }// END OF CCS_QUANTITY
  13470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13471. }
  13472. else if(gunType[gun_index] == 'G')
  13473. {
  13474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13475. {
  13476. tempIndex = ((gun_index==2) ? 1: 0);
  13477. }
  13478. else
  13479. {
  13480. tempIndex = gun_index;
  13481. }
  13482. for (int index = 0; index < GB_QUANTITY; index++)
  13483. {
  13484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13485. {
  13486. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13487. }
  13488. }// END OF GB_QUANTITY
  13489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13490. }
  13491. else
  13492. {
  13493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13494. {
  13495. tempIndex = 2;
  13496. }
  13497. else
  13498. {
  13499. tempIndex = gun_index;
  13500. }
  13501. for (int index = 0; index < AC_QUANTITY; index++)
  13502. {
  13503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13504. {
  13505. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13506. }
  13507. }// END OF AC_QUANTITY
  13508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13509. }
  13510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13513. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13516. //2.3 Power.Active.Export
  13517. //idx_sample=3;
  13518. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13519. if(gunType[gun_index] == 'J')
  13520. {
  13521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13522. {
  13523. tempIndex = ((gun_index==2) ? 1: 0);
  13524. }
  13525. else
  13526. {
  13527. tempIndex = gun_index;
  13528. }
  13529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13530. {
  13531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13532. {
  13533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13534. }
  13535. } // End for CHAdeMO_QUANTITY
  13536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13537. }
  13538. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13539. {
  13540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13541. {
  13542. tempIndex = ((gun_index==2) ? 1: 0);
  13543. }
  13544. else
  13545. {
  13546. tempIndex = gun_index;
  13547. }
  13548. for (int index = 0; index < CCS_QUANTITY; index++)
  13549. {
  13550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13551. {
  13552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13553. }
  13554. } // END for CCS_QUANTITY
  13555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13556. }
  13557. else if(gunType[gun_index] == 'G')
  13558. {
  13559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13560. {
  13561. tempIndex = ((gun_index==2) ? 1: 0);
  13562. }
  13563. else
  13564. {
  13565. tempIndex = gun_index;
  13566. }
  13567. for (int index = 0; index < GB_QUANTITY; index++)
  13568. {
  13569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13570. {
  13571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13572. }
  13573. }// END for GB_QUANTITY
  13574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13575. }
  13576. else
  13577. {
  13578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13579. {
  13580. tempIndex = 2;
  13581. }
  13582. else
  13583. {
  13584. tempIndex = gun_index;
  13585. }
  13586. for (int index = 0; index < AC_QUANTITY; index++)
  13587. {
  13588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13589. {
  13590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13591. }
  13592. } // END for AC_QUANTITY
  13593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13594. }
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13598. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13601. //2.4 Voltage
  13602. //idx_sample=4;
  13603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13604. if(gunType[gun_index] == 'J')
  13605. {
  13606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13607. {
  13608. tempIndex = ((gun_index==2) ? 1: 0);
  13609. }
  13610. else
  13611. {
  13612. tempIndex = gun_index;
  13613. }
  13614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13615. {
  13616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13617. {
  13618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13619. }
  13620. } // END OF FOR CHAdeMO_QUANTITY
  13621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13622. }
  13623. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13624. {
  13625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13626. {
  13627. tempIndex = ((gun_index==2) ? 1: 0);
  13628. }
  13629. else
  13630. {
  13631. tempIndex = gun_index;
  13632. }
  13633. for (int index = 0; index < CCS_QUANTITY; index++)
  13634. {
  13635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13636. {
  13637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13638. }
  13639. } // END OF FOR CCS_QUANTITY
  13640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13641. }
  13642. else if(gunType[gun_index] == 'G')
  13643. {
  13644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13645. {
  13646. tempIndex = ((gun_index==2) ? 1: 0);
  13647. }
  13648. else
  13649. {
  13650. tempIndex = gun_index;
  13651. }
  13652. for (int index = 0; index < GB_QUANTITY; index++)
  13653. {
  13654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13655. {
  13656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13657. }
  13658. } // END OF FOR GB_QUANTITY
  13659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13660. }
  13661. else
  13662. {
  13663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13664. {
  13665. tempIndex = 2;
  13666. }
  13667. else
  13668. {
  13669. tempIndex = gun_index;
  13670. }
  13671. for (int index = 0; index < AC_QUANTITY; index++)
  13672. {
  13673. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13674. {
  13675. 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
  13676. }
  13677. } // END OF FOR AC_QUANTITY
  13678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13679. }
  13680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13683. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13686. //2.5 SoC
  13687. //idx_sample=5;
  13688. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13689. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13690. {
  13691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13692. {
  13693. tempIndex = ((gun_index==2) ? 1: 0);
  13694. }
  13695. else
  13696. {
  13697. tempIndex = gun_index;
  13698. }
  13699. if(gunType[gun_index] == 'J')
  13700. {
  13701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13702. {
  13703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13704. {
  13705. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13706. }
  13707. }
  13708. }
  13709. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13710. {
  13711. for (int index = 0; index < CCS_QUANTITY; index++)
  13712. {
  13713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13714. {
  13715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13716. }
  13717. }
  13718. }
  13719. else if(gunType[gun_index] == 'G')
  13720. {
  13721. for (int index = 0; index < GB_QUANTITY; index++)
  13722. {
  13723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13724. {
  13725. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13726. }
  13727. }
  13728. }
  13729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13735. } // END FOR DC CASE
  13736. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13737. {
  13738. sprintf(queuedata,"%d,[%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\"}]}]}]"
  13739. ,gun_index+1
  13740. ,MESSAGE_TYPE_CALL
  13741. ,guid
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13746. ,"PowerLoss"
  13747. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13790. );
  13791. }
  13792. else
  13793. {
  13794. sprintf(queuedata,"%d,[%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\"}]}]}]"
  13795. ,gun_index+1
  13796. ,MESSAGE_TYPE_CALL
  13797. ,guid
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13802. ,"PowerLoss"
  13803. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13839. );
  13840. }
  13841. // Check File "TempStopTransaction" Exist
  13842. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13843. {
  13844. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13845. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13846. }
  13847. else
  13848. {
  13849. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13850. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13851. if(log == NULL)
  13852. {
  13853. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13854. return ;
  13855. }
  13856. else
  13857. {
  13858. fclose(log);
  13859. }
  13860. }
  13861. //Add TempStopTransaction | Update TempStopTransaction
  13862. // open file for writing
  13863. FILE *outfile;
  13864. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13865. //DEBUG_INFO("data = %s\n", queuedata);
  13866. fputs(queuedata, outfile);
  13867. fputs("\n", outfile);
  13868. fclose (outfile);
  13869. }
  13870. void checkTempStopTransaction(int gun_index)
  13871. {
  13872. FILE *fptr1;
  13873. char ch;
  13874. char str[1200]={0};
  13875. char guid[37]={0};
  13876. char tempdata[65]={0};
  13877. char connectorStr[2]={0};
  13878. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13879. //TempStopTransaction格式: 槍號,StopTransaction封包
  13880. if (!fptr1)
  13881. {
  13882. //printf(" File not found or unable to open the input file!!\n");
  13883. return ;
  13884. }
  13885. ch=fgetc(fptr1);
  13886. //printf(" Now the content of the file %s is : \n",fname);
  13887. rewind(fptr1);
  13888. if(ch!=EOF)
  13889. {
  13890. // copy all contents to the temporary file except the specific line
  13891. while (fgets(str, 1200, fptr1) != NULL)
  13892. {
  13893. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13894. if(str[0]=='\0')
  13895. {
  13896. break;
  13897. }
  13898. //TempStopTransaction格式: 槍號,StopTransaction封包
  13899. strncpy(connectorStr, str, 1);
  13900. if(atoi(connectorStr) != (gun_index+1))
  13901. {
  13902. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13903. return ;
  13904. }
  13905. //random_uuid(guid);
  13906. strncpy(guid, str+6, 36); //copy guid
  13907. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13908. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13909. {
  13910. DEBUG_INFO("StopTransaction mapitem pass\n");
  13911. }
  13912. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13913. memset(str,0,ARRAY_SIZE(str));
  13914. }
  13915. }
  13916. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13917. fclose(fptr1);
  13918. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13919. }
  13920. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13921. {
  13922. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13923. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13924. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13925. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13926. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13927. }
  13928. int GetWebSocketPingInterval(void)
  13929. {
  13930. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13931. }
  13932. int GetServerSign(void)
  13933. {
  13934. return server_sign;
  13935. }
  13936. void SetServerSign(int value)
  13937. {
  13938. server_sign = value;
  13939. }
  13940. int GetBootNotificationInterval(void)
  13941. {
  13942. return BootNotificationInterval;
  13943. }
  13944. int GetInternetConn(void)
  13945. {
  13946. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13947. }
  13948. void InitialSystemValue(void)
  13949. {
  13950. int connectorIndex = 0;
  13951. //int valueASCII = 0;
  13952. server_cycle_Status = 120;
  13953. gunTotalNumber=0;
  13954. SystemInitial = 0;
  13955. localversion=0;
  13956. BootNotificationInterval = 0;
  13957. authorizeRetryTimes = 0;
  13958. GunStatusInterval = 10;
  13959. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13960. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13961. //Hear Beat
  13962. HeartBeatWithNOResponse = 0;
  13963. HeartBeatCountPerHour = 0;
  13964. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  13965. FirstHeartBeat = 0;
  13966. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  13967. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  13968. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  13969. memset(statusModeChage, 0, sizeof(statusModeChage));
  13970. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13971. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13972. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13973. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13974. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13975. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13976. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13977. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13978. memset(gunType, 0, sizeof(gunType));
  13979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13980. {
  13981. //check connector / socket type (index: 8, 9, 10)
  13982. for(int index=7; index <10 ; index++)
  13983. {
  13984. if(index != 8)
  13985. {
  13986. // DC Connector
  13987. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13988. {
  13989. SystemInitial = SystemInitial + 1;
  13990. gunTotalNumber = gunTotalNumber + 1;
  13991. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13992. connectorIndex = connectorIndex + 1;
  13993. }
  13994. }
  13995. else
  13996. {
  13997. // AC Connector
  13998. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13999. {
  14000. SystemInitial = SystemInitial + 1;
  14001. gunTotalNumber = gunTotalNumber + 1;
  14002. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14003. connectorIndex = connectorIndex + 1;
  14004. }
  14005. }
  14006. }
  14007. //DEBUG_INFO("DC ...\n");
  14008. }
  14009. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14010. {
  14011. //check connector / socket type (index: 8, 9, 10)
  14012. for(int index=7; index <10 ; index++)
  14013. {
  14014. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14015. {
  14016. SystemInitial = SystemInitial + 1;
  14017. gunTotalNumber = gunTotalNumber + 1;
  14018. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14019. connectorIndex = connectorIndex + 1;
  14020. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14021. }
  14022. }
  14023. }
  14024. //Status && ConnectorPlugIn Setting
  14025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14026. {
  14027. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14028. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14029. }
  14030. for (int index = 0; index < CCS_QUANTITY; index++)
  14031. {
  14032. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14033. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14034. }
  14035. for (int index = 0; index < GB_QUANTITY; index++)
  14036. {
  14037. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14038. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14039. }
  14040. for (int index = 0; index < AC_QUANTITY; index++)
  14041. {
  14042. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14043. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14044. }
  14045. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14046. {
  14047. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14048. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14049. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14050. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14051. }
  14052. // Charger PRE_SYS_MODE
  14053. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  14054. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14055. clientTime.Heartbeat=time((time_t*)NULL);
  14056. sleep(1);
  14057. }
  14058. void LWS_Send(char * str)
  14059. {
  14060. //=====================================================
  14061. // Check InternetConn 0: disconnected, 1: connected
  14062. //====================================================
  14063. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14064. {
  14065. DEBUG_INFO("offline now !!!\n");
  14066. return;
  14067. }
  14068. pthread_mutex_lock(&lock_send);
  14069. memset(SendBuffer, 0, SendBufLen);
  14070. sprintf((char *)SendBuffer, "%s", str);
  14071. pthread_mutex_unlock(&lock_send);
  14072. lws_callback_on_writable(wsi_client);
  14073. lws_service(context, 0);
  14074. //sleep(1);
  14075. }