MessageHandler.c 629 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266
  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 = 1;
  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. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2108. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2109. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2110. }
  2111. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2112. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2113. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2114. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2115. }
  2116. if(line)
  2117. free(line);
  2118. }
  2119. //==========================================
  2120. // Init all share memory
  2121. //==========================================
  2122. int InitShareMemory()
  2123. {
  2124. int result = PASS;
  2125. int MeterSMId;
  2126. //creat ShmSysConfigAndInfo
  2127. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2128. {
  2129. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2130. result = FAIL;
  2131. }
  2132. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2133. {
  2134. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2135. result = FAIL;
  2136. }
  2137. else
  2138. {}
  2139. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2140. {
  2141. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2142. result = FAIL;
  2143. }
  2144. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2145. {
  2146. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2147. result = FAIL;
  2148. }
  2149. else
  2150. {}
  2151. //creat ShmPsuData
  2152. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2153. {
  2154. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2155. result = FAIL;
  2156. }
  2157. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2158. {
  2159. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2160. result = FAIL;
  2161. }
  2162. else
  2163. {}
  2164. //creat ShmOCPP16Data
  2165. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2166. {
  2167. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2168. result = FAIL;
  2169. }
  2170. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2171. {
  2172. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2173. result = FAIL;
  2174. }
  2175. else
  2176. {}
  2177. /****************************** For Initial Settings************************************************/
  2178. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2179. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2180. // allocate Configuration memory address
  2181. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2182. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2183. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2184. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2185. //offline MeterValue Interval
  2186. TempMeterValueInterval = 0;
  2187. return result;
  2188. }
  2189. int ProcessShareMemory()
  2190. {
  2191. if(InitShareMemory() == FAIL)
  2192. {
  2193. DEBUG_ERROR("InitShareMemory NG\n");
  2194. if(ShmStatusCodeData!=NULL)
  2195. {
  2196. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2197. }
  2198. sleep(5);
  2199. return FAIL;
  2200. }
  2201. return PASS;
  2202. }
  2203. //---------------------common routine---------------------------//
  2204. int isOFFline(void)
  2205. {
  2206. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2207. {
  2208. if(TempMeterValueInterval >= 2 )
  2209. {
  2210. TempMeterValueInterval = 0;
  2211. return TRUE;
  2212. }
  2213. else
  2214. {
  2215. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2216. return FALSE;
  2217. }
  2218. }
  2219. else
  2220. {
  2221. return FALSE;
  2222. }
  2223. }
  2224. //---------------------------------------------
  2225. // new:
  2226. // enum SYSTEM_STATUS
  2227. // {
  2228. // SYS_MODE_BOOTING = 0,
  2229. // SYS_MODE_IDLE = 1,
  2230. // SYS_MODE_AUTHORIZING = 2,
  2231. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2232. // SYS_MODE_REASSIGN = 4,
  2233. // SYS_MODE_PREPARING = 5,
  2234. // SYS_MODE_PREPARE_FOR_EV = 6,
  2235. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2236. // SYS_MODE_CHARGING = 8,
  2237. // SYS_MODE_TERMINATING = 9,
  2238. // SYS_MODE_COMPLETE = 10,
  2239. // SYS_MODE_ALARM = 11,
  2240. // SYS_MODE_FAULT = 12,
  2241. // SYS_MODE_RESERVATION = 13,
  2242. // SYS_MODE_BOOKING = 14,
  2243. // SYS_MODE_MAINTAIN = 15,
  2244. // SYS_MODE_DEBUG = 16,
  2245. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2246. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2247. // SYS_MODE_UPDATE = 19
  2248. // };
  2249. //
  2250. //
  2251. //-----------------------------------------
  2252. void CheckSystemValue(void)
  2253. {
  2254. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2255. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2256. char filenmae[100]={0};
  2257. char str[100]={0};
  2258. int tempIndex = 0;
  2259. //===============================
  2260. // send Heartbeat
  2261. //===============================
  2262. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2263. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2264. {
  2265. clientTime.Heartbeat=time((time_t*)NULL);
  2266. if(server_sign == TRUE)
  2267. {
  2268. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2269. }
  2270. else
  2271. {
  2272. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2273. }
  2274. }
  2275. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2276. {
  2277. //parameter for test
  2278. sendHeartbeatRequest(0);
  2279. //==============================================
  2280. // Reset Waiting Time
  2281. //==============================================
  2282. clientTime.Heartbeat=time((time_t*)NULL);
  2283. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2284. }
  2285. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2286. {
  2287. //===============================
  2288. // CSU Trigger Reset Conf
  2289. //===============================
  2290. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2291. {
  2292. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2293. }
  2294. //===============================
  2295. // CSU Trigger Authorize Request
  2296. //===============================
  2297. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2298. {
  2299. sendAuthorizeRequest(0);
  2300. authorizeRetryTimes = authorizeRetryTimes + 1;
  2301. if(authorizeRetryTimes < 3)
  2302. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2303. }
  2304. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2305. {
  2306. authorizeRetryTimes = 0;
  2307. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2308. server_sign = FALSE;
  2309. }
  2310. 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))
  2311. {
  2312. sendAuthorizeRequest(0);
  2313. }
  2314. //===============================
  2315. // CSU Trigger Smart Charging Profilw
  2316. //===============================
  2317. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2318. {
  2319. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2320. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2321. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2322. }
  2323. //==============================================
  2324. // Charger start transaction
  2325. //==============================================
  2326. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2327. {
  2328. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2329. sendStartTransactionRequest(gun_index);
  2330. clientTime.StartTransaction = time((time_t*)NULL);
  2331. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2332. }
  2333. //==============================================
  2334. // Charger stop transaction
  2335. //==============================================
  2336. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2337. {
  2338. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2339. sendStopTransactionRequest(gun_index);
  2340. clientTime.StopTransaction = time((time_t*)NULL);
  2341. }
  2342. //==============================================
  2343. // Charger status report
  2344. //==============================================
  2345. //--- Check Mode Change ---//
  2346. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2347. if(gunType[gun_index] == 'J')
  2348. {
  2349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2350. {
  2351. tempIndex = ((gun_index==2) ? 1: 0);
  2352. }
  2353. else
  2354. {
  2355. tempIndex = gun_index;
  2356. }
  2357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2358. {
  2359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2360. {
  2361. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[gun_index]) )
  2362. {
  2363. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2364. ChademoPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2365. ChademoPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2366. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2367. statusModeChage[gun_index] = TRUE;
  2368. }
  2369. #if 1 // for TempStopTransaction
  2370. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2371. {
  2372. checkTempStopTransaction(gun_index);
  2373. }
  2374. #endif
  2375. }
  2376. }
  2377. }
  2378. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2379. {
  2380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2381. {
  2382. tempIndex = ((gun_index==2) ? 1: 0);
  2383. }
  2384. else
  2385. {
  2386. tempIndex = gun_index;
  2387. }
  2388. for (int index = 0; index < CCS_QUANTITY; index++)
  2389. {
  2390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2391. {
  2392. 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]*/ )
  2393. {
  2394. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2395. CcsPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2396. CcsPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2397. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2398. statusModeChage[gun_index] = TRUE;
  2399. }
  2400. #if 1 // for TempStopTransaction
  2401. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2402. {
  2403. checkTempStopTransaction(gun_index);
  2404. }
  2405. #endif
  2406. }
  2407. }
  2408. }
  2409. else if(gunType[gun_index] == 'G')
  2410. {
  2411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2412. {
  2413. tempIndex = ((gun_index==2) ? 1: 0);
  2414. }
  2415. else
  2416. {
  2417. tempIndex = gun_index;
  2418. }
  2419. for (int index = 0; index < GB_QUANTITY; index++)
  2420. {
  2421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2422. {
  2423. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[gun_index]) )
  2424. {
  2425. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2426. GbPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2427. GbPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2428. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2429. statusModeChage[gun_index] = TRUE;
  2430. }
  2431. #if 1 // for TempStopTransaction
  2432. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2433. {
  2434. checkTempStopTransaction(gun_index);
  2435. }
  2436. #endif
  2437. }
  2438. }
  2439. }
  2440. else
  2441. {
  2442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2443. {
  2444. tempIndex = 2;
  2445. }
  2446. else
  2447. {
  2448. tempIndex = gun_index;
  2449. }
  2450. for (int index = 0; index < AC_QUANTITY; index++)
  2451. {
  2452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2453. {
  2454. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[gun_index]) )
  2455. {
  2456. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2457. AcPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2458. AcPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2459. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2460. statusModeChage[gun_index] = TRUE;
  2461. }
  2462. #if 1 // for TempStopTransaction
  2463. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2464. {
  2465. checkTempStopTransaction(gun_index);
  2466. }
  2467. #endif
  2468. }
  2469. }// END
  2470. }
  2471. if(isWebsocketSendable &&
  2472. (((server_sign == TRUE) && (SystemInitial > 0)) ||
  2473. ((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))))) )
  2474. {
  2475. if(SystemInitial > 0)
  2476. SystemInitial = SystemInitial -1;
  2477. sendStatusNotificationRequest(gun_index);
  2478. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2479. statusModeChage[gun_index] = FALSE;
  2480. }
  2481. //==============================================
  2482. // Meter report
  2483. //==============================================
  2484. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) ||
  2485. (((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)))
  2486. {
  2487. //check Transaction active
  2488. if(gunType[gun_index] == 'J')
  2489. {
  2490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2491. {
  2492. tempIndex = ((gun_index==2) ? 1: 0);
  2493. }
  2494. else
  2495. {
  2496. tempIndex = gun_index;
  2497. }
  2498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2499. {
  2500. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2501. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2502. {
  2503. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2504. {
  2505. reqSampleMeter[gun_index] = 1;
  2506. }
  2507. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2508. {
  2509. reqClockAlignMeter[gun_index] = 1;
  2510. }
  2511. }
  2512. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2513. {
  2514. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2515. if((access(filenmae,F_OK))!=-1)
  2516. {
  2517. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2518. sprintf(str,"rm -f %s",filenmae);
  2519. system(str);
  2520. }
  2521. }
  2522. }// End for CHAdeMO
  2523. }
  2524. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2525. {
  2526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2527. {
  2528. tempIndex = ((gun_index==2) ? 1: 0);
  2529. }
  2530. else
  2531. {
  2532. tempIndex = gun_index;
  2533. }
  2534. for (int index = 0; index < CCS_QUANTITY; index++)
  2535. {
  2536. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2537. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2538. {
  2539. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2540. {
  2541. reqSampleMeter[gun_index] = 1;
  2542. }
  2543. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2544. {
  2545. reqClockAlignMeter[gun_index] = 1;
  2546. }
  2547. }
  2548. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2549. {
  2550. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2551. if((access(filenmae,F_OK))!=-1)
  2552. {
  2553. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2554. sprintf(str,"rm -f %s",filenmae);
  2555. system(str);
  2556. }
  2557. }
  2558. } // End for CCS
  2559. }
  2560. else if(gunType[gun_index] == 'G')
  2561. {
  2562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2563. {
  2564. tempIndex = ((gun_index==2) ? 1: 0);
  2565. }
  2566. else
  2567. {
  2568. tempIndex = gun_index;
  2569. }
  2570. for (int index = 0; index < GB_QUANTITY; index++)
  2571. {
  2572. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2573. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2574. {
  2575. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2576. {
  2577. reqSampleMeter[gun_index] = 1;
  2578. }
  2579. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2580. {
  2581. reqClockAlignMeter[gun_index] = 1;
  2582. }
  2583. }
  2584. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2585. {
  2586. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2587. if((access(filenmae,F_OK))!=-1)
  2588. {
  2589. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2590. sprintf(str,"rm -f %s",filenmae);
  2591. system(str);
  2592. }
  2593. }
  2594. }// End for GB
  2595. }
  2596. else
  2597. {
  2598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2599. {
  2600. tempIndex = 2;
  2601. }
  2602. else
  2603. {
  2604. tempIndex = gun_index;
  2605. }
  2606. for (int index = 0; index < AC_QUANTITY; index++)
  2607. {
  2608. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2609. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2610. {
  2611. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2612. {
  2613. reqSampleMeter[gun_index] = 1;
  2614. }
  2615. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2616. {
  2617. reqClockAlignMeter[gun_index] = 1;
  2618. }
  2619. }
  2620. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2621. {
  2622. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2623. if((access(filenmae,F_OK))!=-1)
  2624. {
  2625. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2626. sprintf(str,"rm -f %s",filenmae);
  2627. system(str);
  2628. }
  2629. }
  2630. }//End for AC
  2631. }
  2632. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2633. if(reqSampleMeter[gun_index] == 1)
  2634. {
  2635. sendMeterValuesRequest(gun_index);
  2636. storeTempStopTransaction(gun_index);
  2637. }
  2638. else if(reqClockAlignMeter[gun_index] == 1)
  2639. {
  2640. sendMeterValuesRequest(gun_index);
  2641. }
  2642. sleep(1);
  2643. }
  2644. //==============================================
  2645. // Check Connector reserved
  2646. //==============================================
  2647. //===============================
  2648. // Check if Reserve is expired
  2649. //===============================
  2650. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2651. {
  2652. double diff_t;
  2653. struct tm tp;
  2654. // current time
  2655. time_t t = time(NULL);
  2656. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2657. tp.tm_isdst = -1;
  2658. time_t utc = mktime(&tp);
  2659. diff_t = difftime(utc, t);
  2660. if(diff_t <= 0)
  2661. {
  2662. DEBUG_INFO("reserve expired.\n");
  2663. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2664. }
  2665. }//END OF Check if Reserve is expired
  2666. //==========================================
  2667. // csu trigger FirmwareStatusNotificationReq
  2668. //==========================================
  2669. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2670. {
  2671. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2672. }
  2673. //==========================================
  2674. // csu trigger CancelReservationConf
  2675. //==========================================
  2676. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2677. {
  2678. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2679. }
  2680. //==========================================
  2681. // csu trigger ChangeAvailabilityConf
  2682. //==========================================
  2683. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2684. {
  2685. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2686. }
  2687. //==========================================
  2688. // csu trigger UnlockConnectorConf
  2689. //==========================================
  2690. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2691. {
  2692. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2693. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2694. }
  2695. //==========================================
  2696. // csu trigger ReserveNowConf
  2697. //==========================================
  2698. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2699. {
  2700. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2701. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2702. }
  2703. //==========================================
  2704. // csu trigger DataTransferReq
  2705. //==========================================
  2706. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2707. {
  2708. sendDataTransferRequest(gun_index);
  2709. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2710. }
  2711. }
  2712. }
  2713. //==========================================
  2714. // send request routine
  2715. //==========================================
  2716. int sendAuthorizeRequest(int gun_index)
  2717. {
  2718. mtrace();
  2719. int result = FAIL;
  2720. char message[100]={0};
  2721. char guid[37];
  2722. char tempdata[65]={0};
  2723. DEBUG_INFO("sendAuthorizeRequest...\n");
  2724. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2725. //Local Authorize
  2726. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2727. {
  2728. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2729. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2730. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2731. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2732. result = PASS;
  2733. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2734. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2735. authorizeRetryTimes = 0;
  2736. return result;
  2737. }
  2738. 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))||
  2739. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2740. {
  2741. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2742. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2743. {
  2744. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2745. {
  2746. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2747. }
  2748. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2749. {
  2750. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2751. }
  2752. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2753. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2754. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2755. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2756. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2757. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2758. authorizeRetryTimes = 0;
  2759. return result;
  2760. }
  2761. else
  2762. {
  2763. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2764. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2767. result = PASS;
  2768. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2769. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2770. authorizeRetryTimes = 0;
  2771. return result;
  2772. }
  2773. }
  2774. //initailize struct Authorize
  2775. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2776. //get data from shared memory
  2777. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2778. random_uuid(guid);
  2779. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2780. LWS_Send(message);
  2781. sprintf(tempdata, "Authorize,%d", gun_index);
  2782. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2783. {
  2784. result = PASS;
  2785. DEBUG_INFO("Authorize mapItem pass\n");
  2786. }
  2787. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2788. return result;
  2789. }
  2790. int sendBootNotificationRequest(void)
  2791. {
  2792. mtrace();
  2793. int result = FAIL;
  2794. char message[500]={0}, payload[700]={0};
  2795. char guid[37]={0};
  2796. char tempdata[65]={0};
  2797. int IsGunCharging = FALSE;
  2798. //check Transaction active
  2799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2800. {
  2801. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2802. {
  2803. IsGunCharging = TRUE;
  2804. }
  2805. }
  2806. for (int index = 0; index < CCS_QUANTITY; index++)
  2807. {
  2808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2809. {
  2810. IsGunCharging = TRUE;
  2811. }
  2812. }
  2813. for (int index = 0; index < GB_QUANTITY; index++)
  2814. {
  2815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2816. {
  2817. IsGunCharging = TRUE;
  2818. }
  2819. }
  2820. for (int index = 0; index < AC_QUANTITY; index++)
  2821. {
  2822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2823. {
  2824. IsGunCharging = TRUE;
  2825. }
  2826. }
  2827. if(IsGunCharging == TRUE)
  2828. {
  2829. server_sign = TRUE;
  2830. return result;
  2831. }
  2832. // Fill BootNotification fields
  2833. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2834. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2835. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2836. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2837. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2838. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2839. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2840. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2841. ShmOCPP16Data->ChargeBoxId
  2842. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2843. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2844. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2845. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2846. ,ShmOCPP16Data->BootNotification.CpIccid
  2847. ,ShmOCPP16Data->BootNotification.CpImsi);
  2848. random_uuid(guid);
  2849. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2850. LWS_Send(message);
  2851. sprintf(tempdata, "BootNotification,0");
  2852. 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*/)
  2853. {
  2854. result = PASS;
  2855. }
  2856. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2857. strcpy(queuedata,message);
  2858. return result;
  2859. }
  2860. int sendDataTransferRequest(int gun_index)
  2861. {
  2862. mtrace();
  2863. char message[1000]={0};
  2864. char guid[37]={0};
  2865. char tempdata[65]={0};
  2866. int result = FAIL;
  2867. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2868. random_uuid(guid);
  2869. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2870. MESSAGE_TYPE_CALL,
  2871. guid,
  2872. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2873. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2874. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2875. LWS_Send(message);
  2876. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2877. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2878. {
  2879. result = PASS;
  2880. DEBUG_INFO("DataTransfer mapItem pass\n");
  2881. }
  2882. return result;
  2883. }
  2884. int sendDiagnosticsStatusNotificationRequest(char *status)
  2885. {
  2886. mtrace();
  2887. int result = FAIL;
  2888. char message[110]={0};
  2889. char guid[37]={0};
  2890. char tempdata[65]={0};
  2891. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2892. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2893. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2894. random_uuid(guid);
  2895. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2896. LWS_Send(message);
  2897. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2898. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2899. {
  2900. result = PASS;
  2901. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2902. }
  2903. //#ifdef SystemLogMessage
  2904. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2905. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2906. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2907. //#endif
  2908. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2909. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2910. //record status
  2911. if(strcmp(status,"Idle")==0)
  2912. {
  2913. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2914. }
  2915. else if(strcmp(status,"Uploaded")==0)
  2916. {
  2917. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2918. }
  2919. else if(strcmp(status,"UploadFailed")==0)
  2920. {
  2921. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2922. }
  2923. else if(strcmp(status,"Uploading")==0)
  2924. {
  2925. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2926. }
  2927. return result;
  2928. }
  2929. int sendFirmwareStatusNotificationRequest(char *status)
  2930. {
  2931. mtrace();
  2932. int result = FAIL;
  2933. char message[110]={0};
  2934. char guid[37]={0};
  2935. char tempdata[65]={0};
  2936. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2937. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2938. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2939. random_uuid(guid);
  2940. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2941. LWS_Send(message);
  2942. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2943. 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*/)
  2944. {
  2945. result = PASS;
  2946. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2947. }
  2948. //#ifdef SystemLogMessage
  2949. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2950. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2951. //#endif
  2952. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2953. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2954. //record status
  2955. if(strcmp(status,"Downloaded")==0)
  2956. {
  2957. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2958. }
  2959. else if(strcmp(status,"DownloadFailed")==0)
  2960. {
  2961. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2962. }
  2963. else if(strcmp(status,"Downloading")==0)
  2964. {
  2965. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2966. }
  2967. else if(strcmp(status,"Idle")==0)
  2968. {
  2969. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2970. }
  2971. else if(strcmp(status,"InstallationFailed")==0)
  2972. {
  2973. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2974. }
  2975. else if(strcmp(status,"Installing")==0)
  2976. {
  2977. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2978. }
  2979. else if(strcmp(status,"Installed")==0)
  2980. {
  2981. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2982. }
  2983. return result;
  2984. }
  2985. int sendHeartbeatRequest(int gun_index)
  2986. {
  2987. mtrace();
  2988. int result = FAIL;
  2989. char message[80]={0};
  2990. char guid[37]={0};
  2991. char tempdata[65]={0};
  2992. random_uuid(guid);
  2993. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2994. , MESSAGE_TYPE_CALL
  2995. , guid );
  2996. LWS_Send(message);
  2997. sprintf(tempdata, "Heartbeat,%d", 0);
  2998. 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*/)
  2999. {
  3000. result = PASS;
  3001. }
  3002. return result;
  3003. }
  3004. int sendStartTransactionRequest(int gun_index)
  3005. {
  3006. mtrace();
  3007. int result = FAIL;
  3008. char message[250]={0};
  3009. char guid[37]={0};
  3010. struct timeval tmnow;
  3011. struct tm *tm;
  3012. char buf[28];//, usec_buf[6];
  3013. char tempdata[65]={0};
  3014. int tempIndex = 0;
  3015. DEBUG_INFO("sendStartTransactionRequest...\n");
  3016. gettimeofday(&tmnow, NULL);
  3017. time_t t;
  3018. t = time(NULL);
  3019. /*UTC time and date*/
  3020. tm = gmtime(&t);
  3021. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3022. #if 0 // remove temporally
  3023. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3024. strcat(buf,".");
  3025. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3026. strcat(buf,usec_buf);
  3027. #endif
  3028. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3029. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3030. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3031. // clear StartTransaction Response
  3032. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3033. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3034. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3035. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3036. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3037. if(gunType[gun_index] == 'J')
  3038. {
  3039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3040. {
  3041. tempIndex = ((gun_index==2) ? 1: 0);
  3042. }
  3043. else
  3044. {
  3045. tempIndex = gun_index;
  3046. }
  3047. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3048. {
  3049. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3050. {
  3051. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  3052. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3053. }
  3054. }
  3055. }
  3056. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3057. {
  3058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3059. {
  3060. tempIndex = ((gun_index==2) ? 1: 0);
  3061. }
  3062. else
  3063. {
  3064. tempIndex = gun_index;
  3065. }
  3066. for (int index = 0; index < CCS_QUANTITY; index++)
  3067. {
  3068. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3069. {
  3070. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  3071. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3072. }
  3073. }
  3074. }
  3075. else if(gunType[gun_index] == 'G')
  3076. {
  3077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3078. {
  3079. tempIndex = ((gun_index==2) ? 1: 0);
  3080. }
  3081. else
  3082. {
  3083. tempIndex = gun_index;
  3084. }
  3085. for (int index = 0; index < GB_QUANTITY; index++)
  3086. {
  3087. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3088. {
  3089. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  3090. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3091. }
  3092. }
  3093. }
  3094. else
  3095. {
  3096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3097. {
  3098. tempIndex = 2;
  3099. }
  3100. else
  3101. {
  3102. tempIndex = gun_index;
  3103. }
  3104. for (int index = 0; index < AC_QUANTITY; index++)
  3105. {
  3106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3107. {
  3108. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3109. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3110. }
  3111. }
  3112. }
  3113. random_uuid(guid);
  3114. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3115. {
  3116. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3117. , gun_index +1
  3118. , MESSAGE_TYPE_CALL
  3119. , guid
  3120. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3121. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3122. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3123. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3124. }
  3125. else
  3126. {
  3127. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3128. , gun_index +1
  3129. , MESSAGE_TYPE_CALL
  3130. , guid
  3131. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3132. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3133. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3134. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3135. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3136. }
  3137. #if 1
  3138. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3139. 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*/)
  3140. {
  3141. result = PASS;
  3142. }
  3143. #endif
  3144. strcpy(queuedata, message);
  3145. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3146. /*
  3147. if(GetTransactionQueueNum() == 1)
  3148. {
  3149. LWS_Send(message + 2);
  3150. }*/
  3151. return result;
  3152. }
  3153. int sendStatusNotificationRequest(int gun_index)
  3154. {
  3155. mtrace();
  3156. int result = FAIL;
  3157. char message[600]={0};
  3158. char guid[37];
  3159. int currentStatus = 0;
  3160. struct timeval tmnow;
  3161. struct tm *tm;
  3162. char buf[28];//, usec_buf[6];
  3163. char tempdata[65]={0};
  3164. int tempIndex = 0;
  3165. gettimeofday(&tmnow, NULL);
  3166. time_t t;
  3167. t = time(NULL);
  3168. /*UTC time and date*/
  3169. tm = gmtime(&t);
  3170. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3171. #if 0 // remove temporally
  3172. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3173. strcat(buf,".");
  3174. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3175. strcat(buf,usec_buf);
  3176. #endif
  3177. printf("%s",buf);
  3178. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3179. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3180. // it's option
  3181. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3182. /*
  3183. enum _SYSTEM_STATUS
  3184. {
  3185. S_BOOTING = 0,
  3186. S_IDLE, = 1
  3187. S_AUTHORIZING, =2
  3188. S_REASSIGN_CHECK, =3
  3189. S_REASSIGN, =4
  3190. S_PRECHARGE, =5
  3191. S_PREPARING_FOR_EV, =6
  3192. S_PREPARING_FOR_EVSE, =7
  3193. S_CHARGING, =8
  3194. S_TERMINATING, =9
  3195. S_COMPLETE, =10
  3196. S_ALARM, =11
  3197. S_FAULT =12
  3198. }
  3199. */
  3200. //check Transaction active
  3201. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3202. if(gunType[gun_index] == 'J')
  3203. {
  3204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3205. {
  3206. tempIndex = ((gun_index==2) ? 1: 0);
  3207. }
  3208. else
  3209. {
  3210. tempIndex = gun_index;
  3211. }
  3212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3213. {
  3214. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3215. {
  3216. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3217. {
  3218. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3219. {
  3220. currentStatus = 1; //OCPP Status: Preparing
  3221. }
  3222. else
  3223. {
  3224. currentStatus = 0; //OCPP Status: Available
  3225. }
  3226. }
  3227. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3228. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3229. ) //S_PRECHARGE
  3230. {
  3231. currentStatus = 1; //OCPP Status: Preparing
  3232. }
  3233. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3234. {
  3235. currentStatus = 2; //OCPP Status: Charging
  3236. }
  3237. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3238. {
  3239. currentStatus = 5; //OCPP Status: Finishing
  3240. }
  3241. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3242. {
  3243. currentStatus = 4; //OCPP Status: SuspendedEV
  3244. }
  3245. 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
  3246. {
  3247. currentStatus = 7; //OCPP Status: Unavailable
  3248. }
  3249. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3250. {
  3251. currentStatus = 8; //OCPP Status: Faulted
  3252. }
  3253. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3254. {
  3255. currentStatus = 6; //OCPP Status: Reserved
  3256. }
  3257. } //end of the same index
  3258. }//end of for CHAdeMO_QUANTITY
  3259. }
  3260. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3261. {
  3262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3263. {
  3264. tempIndex = ((gun_index==2) ? 1: 0);
  3265. }
  3266. else
  3267. {
  3268. tempIndex = gun_index;
  3269. }
  3270. for (int index = 0; index < CCS_QUANTITY; index++)
  3271. {
  3272. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3273. {
  3274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3275. {
  3276. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3277. {
  3278. currentStatus = 1; //OCPP Status: Preparing
  3279. }
  3280. else
  3281. {
  3282. currentStatus = 0; //OCPP Status: Available
  3283. }
  3284. }
  3285. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3286. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3287. ) //S_PRECHARGE
  3288. {
  3289. currentStatus = 1; //OCPP Status: Preparing
  3290. }
  3291. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3292. {
  3293. currentStatus = 2; //OCPP Status: Charging
  3294. }
  3295. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3296. {
  3297. currentStatus = 5; //OCPP Status: Finishing
  3298. }
  3299. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3300. {
  3301. currentStatus = 4; //OCPP Status: SuspendedEV
  3302. }
  3303. 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
  3304. {
  3305. currentStatus = 7; //OCPP Status : Unavailable
  3306. }
  3307. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3308. {
  3309. currentStatus = 8; //OCPP Status: Faulted
  3310. }
  3311. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3312. {
  3313. currentStatus = 6; //OCPP Status: Reserved
  3314. }
  3315. } //end of the same index
  3316. } // end of for CCS_QUANTITY
  3317. }
  3318. else if(gunType[gun_index] == 'G')
  3319. {
  3320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3321. {
  3322. tempIndex = ((gun_index==2) ? 1: 0);
  3323. }
  3324. else
  3325. {
  3326. tempIndex = gun_index;
  3327. }
  3328. for (int index = 0; index < GB_QUANTITY; index++)
  3329. {
  3330. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3331. {
  3332. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3333. {
  3334. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3335. {
  3336. currentStatus = 1; //OCPP Status: Preparing
  3337. }
  3338. else
  3339. {
  3340. currentStatus = 0; //OCPP Status: Available
  3341. }
  3342. }
  3343. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3344. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3345. ) //S_PRECHARGE
  3346. {
  3347. currentStatus = 1; //OCPP Status: Preparing
  3348. }
  3349. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3350. {
  3351. currentStatus = 2; //OCPP Status: Charging
  3352. }
  3353. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3354. {
  3355. currentStatus = 5; //OCPP Status: Finishing
  3356. }
  3357. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3358. {
  3359. currentStatus = 4; //OCPP Status: SuspendedEV
  3360. }
  3361. 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
  3362. {
  3363. currentStatus = 7; //OCPP Status: Unavailable
  3364. }
  3365. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3366. {
  3367. currentStatus = 8; //OCPP Status: Faulted
  3368. }
  3369. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3370. {
  3371. currentStatus = 6; //OCPP Status: Reserved
  3372. }
  3373. } //end of the same index
  3374. } // end of for GB_QUANTITY
  3375. }
  3376. else
  3377. {
  3378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3379. {
  3380. tempIndex = 2;
  3381. }
  3382. else
  3383. {
  3384. tempIndex = gun_index;
  3385. }
  3386. for (int index = 0; index < AC_QUANTITY; index++)
  3387. {
  3388. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3389. {
  3390. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3391. {
  3392. 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))
  3393. {
  3394. currentStatus = 1; //OCPP Status: Preparing
  3395. }
  3396. else
  3397. {
  3398. currentStatus = 0; //OCPP Status: Available
  3399. }
  3400. }
  3401. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  3402. {
  3403. currentStatus = 1; //OCPP Status: Preparing
  3404. }
  3405. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3406. {
  3407. currentStatus = 2; //OCPP Status: Charging
  3408. }
  3409. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3410. {
  3411. currentStatus = 5; //OCPP Status: Finishing
  3412. }
  3413. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3414. {
  3415. currentStatus = 4; //OCPP Status: SuspendedEV
  3416. }
  3417. 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
  3418. {
  3419. currentStatus = 7; //OCPP Status: Unavailable
  3420. }
  3421. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3422. {
  3423. currentStatus = 8; //OCPP Status: Faulted
  3424. }
  3425. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3426. {
  3427. currentStatus = 6; //OCPP Status: Reserved
  3428. }
  3429. }//end of the same index
  3430. }//end of for AC_QUANTITY
  3431. }
  3432. //it's option
  3433. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3434. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3435. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3436. random_uuid(guid);
  3437. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3438. , MESSAGE_TYPE_CALL
  3439. , guid
  3440. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3441. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3442. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3443. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3444. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3445. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3446. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3447. LWS_Send(message);
  3448. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3449. 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*/)
  3450. {
  3451. //DEBUG_ERROR("statusNotification mapitem pass");
  3452. result = PASS;
  3453. }
  3454. return result;
  3455. }
  3456. int sendStopTransactionRequest(int gun_index)
  3457. {
  3458. mtrace();
  3459. int result = FAIL;
  3460. //char message[1500]={0};
  3461. char guid[37]={0};
  3462. char tempdata[65]={0};
  3463. int tempIndex = 0;
  3464. //int idx_sample=0;
  3465. DEBUG_ERROR("sendStopTransactionRequest \n");
  3466. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3467. //ENERGY_ACTIVE_IMPORT_REGISTER
  3468. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3469. if(gunType[gun_index] == 'J')
  3470. {
  3471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3472. {
  3473. tempIndex = ((gun_index==2) ? 1: 0);
  3474. }
  3475. else
  3476. {
  3477. tempIndex = gun_index;
  3478. }
  3479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3480. {
  3481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3482. {
  3483. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3484. }
  3485. }// END OF CHAdeMO_QUANTITY
  3486. }
  3487. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3488. {
  3489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3490. {
  3491. tempIndex = ((gun_index==2) ? 1: 0);
  3492. }
  3493. else
  3494. {
  3495. tempIndex = gun_index;
  3496. }
  3497. for (int index = 0; index < CCS_QUANTITY; index++)
  3498. {
  3499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3500. {
  3501. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3502. }
  3503. }// END OF CCS_QUANTITY
  3504. }
  3505. else if(gunType[gun_index] == 'G')
  3506. {
  3507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3508. {
  3509. tempIndex = ((gun_index==2) ? 1: 0);
  3510. }
  3511. else
  3512. {
  3513. tempIndex = gun_index;
  3514. }
  3515. for (int index = 0; index < GB_QUANTITY; index++)
  3516. {
  3517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3518. {
  3519. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3520. }
  3521. }// END OF GB_QUANTITY
  3522. }
  3523. else
  3524. {
  3525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3526. {
  3527. tempIndex = 2;
  3528. }
  3529. else
  3530. {
  3531. tempIndex = gun_index;
  3532. }
  3533. for (int index = 0; index < AC_QUANTITY; index++)
  3534. {
  3535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3536. {
  3537. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3538. }
  3539. }// END OF AC_QUANTITY
  3540. }
  3541. //Stop Transaction Time
  3542. struct timeval tmnow;
  3543. struct tm *tm;
  3544. char buf[28];//, usec_buf[6];
  3545. gettimeofday(&tmnow, NULL);
  3546. time_t t;
  3547. t = time(NULL);
  3548. /*UTC time and date*/
  3549. tm = gmtime(&t);
  3550. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3552. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3553. random_uuid(guid);
  3554. /***********************************transactionData******************************************************/
  3555. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3557. //=================================
  3558. // Transaction_Begin
  3559. //=================================
  3560. // Energy.Active.Export.Interval
  3561. //idx_sample=0;
  3562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3565. 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*/]);
  3566. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3567. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3568. {
  3569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3570. }
  3571. else
  3572. {
  3573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3574. }
  3575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3577. //=================================
  3578. // Transaction_End
  3579. //=================================
  3580. //Current.Export
  3581. //idx_sample=1;
  3582. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3583. if(gunType[gun_index] == 'J')
  3584. {
  3585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3586. {
  3587. tempIndex = ((gun_index==2) ? 1: 0);
  3588. }
  3589. else
  3590. {
  3591. tempIndex = gun_index;
  3592. }
  3593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3594. {
  3595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3596. {
  3597. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3598. }
  3599. }// End of for CHAdeMO_QUANTITY
  3600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3601. }
  3602. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3603. {
  3604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3605. {
  3606. tempIndex = ((gun_index==2) ? 1: 0);
  3607. }
  3608. else
  3609. {
  3610. tempIndex = gun_index;
  3611. }
  3612. for (int index = 0; index < CCS_QUANTITY; index++)
  3613. {
  3614. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3615. {
  3616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3617. }
  3618. }// End of for CCS_QUANTITY
  3619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3620. }
  3621. else if(gunType[gun_index] == 'G')
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3624. {
  3625. tempIndex = ((gun_index==2) ? 1: 0);
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < GB_QUANTITY; index++)
  3632. {
  3633. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3634. {
  3635. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3636. }
  3637. }// End of for GB_QUANTITY
  3638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3639. }
  3640. else
  3641. {
  3642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3643. {
  3644. tempIndex = 2;
  3645. }
  3646. else
  3647. {
  3648. tempIndex = gun_index;
  3649. }
  3650. for (int index = 0; index < AC_QUANTITY; index++)
  3651. {
  3652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3653. {
  3654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3655. }
  3656. }// End of for AC_QUANTITY
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3658. }
  3659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3662. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3665. //Energy.Active.Export.Interval
  3666. //idx_sample=2;
  3667. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3668. if(gunType[gun_index] == 'J')
  3669. {
  3670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3671. {
  3672. tempIndex = ((gun_index==2) ? 1: 0);
  3673. }
  3674. else
  3675. {
  3676. tempIndex = gun_index;
  3677. }
  3678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3679. {
  3680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3681. {
  3682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3683. }
  3684. }// END OF CHAdeMO_QUANTITY
  3685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3686. }
  3687. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3688. {
  3689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3690. {
  3691. tempIndex = ((gun_index==2) ? 1: 0);
  3692. }
  3693. else
  3694. {
  3695. tempIndex = gun_index;
  3696. }
  3697. for (int index = 0; index < CCS_QUANTITY; index++)
  3698. {
  3699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3700. {
  3701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3702. }
  3703. }// END OF CCS_QUANTITY
  3704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3705. }
  3706. else if(gunType[gun_index] == 'G')
  3707. {
  3708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3709. {
  3710. tempIndex = ((gun_index==2) ? 1: 0);
  3711. }
  3712. else
  3713. {
  3714. tempIndex = gun_index;
  3715. }
  3716. for (int index = 0; index < GB_QUANTITY; index++)
  3717. {
  3718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3719. {
  3720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3721. }
  3722. }// END OF GB_QUANTITY
  3723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3724. }
  3725. else
  3726. {
  3727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3728. {
  3729. tempIndex = 2;
  3730. }
  3731. else
  3732. {
  3733. tempIndex = gun_index;
  3734. }
  3735. for (int index = 0; index < AC_QUANTITY; index++)
  3736. {
  3737. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3738. {
  3739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3740. }
  3741. }// END OF AC_QUANTITY
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3743. }
  3744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3747. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3750. //Power.Active.Export
  3751. //idx_sample=3;
  3752. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3753. if(gunType[gun_index] == 'J')
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3756. {
  3757. tempIndex = ((gun_index==2) ? 1: 0);
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3766. {
  3767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3768. }
  3769. } // End for CHAdeMO_QUANTITY
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3771. }
  3772. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3773. {
  3774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3775. {
  3776. tempIndex = ((gun_index==2) ? 1: 0);
  3777. }
  3778. else
  3779. {
  3780. tempIndex = gun_index;
  3781. }
  3782. for (int index = 0; index < CCS_QUANTITY; index++)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3785. {
  3786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3787. }
  3788. } // END for CCS_QUANTITY
  3789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3790. }
  3791. else if(gunType[gun_index] == 'G')
  3792. {
  3793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3794. {
  3795. tempIndex = ((gun_index==2) ? 1: 0);
  3796. }
  3797. else
  3798. {
  3799. tempIndex = gun_index;
  3800. }
  3801. for (int index = 0; index < GB_QUANTITY; index++)
  3802. {
  3803. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3804. {
  3805. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3806. }
  3807. }// END for GB_QUANTITY
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3809. }
  3810. else
  3811. {
  3812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3813. {
  3814. tempIndex = 2;
  3815. }
  3816. else
  3817. {
  3818. tempIndex = gun_index;
  3819. }
  3820. for (int index = 0; index < AC_QUANTITY; index++)
  3821. {
  3822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3823. {
  3824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3825. }
  3826. } // END for AC_QUANTITY
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3828. }
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3832. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3835. //Voltage
  3836. //idx_sample=4;
  3837. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3838. if(gunType[gun_index] == 'J')
  3839. {
  3840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3841. {
  3842. tempIndex = ((gun_index==2) ? 1: 0);
  3843. }
  3844. else
  3845. {
  3846. tempIndex = gun_index;
  3847. }
  3848. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3849. {
  3850. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3851. {
  3852. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3853. }
  3854. } // END OF FOR CHAdeMO_QUANTITY
  3855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3856. }
  3857. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3858. {
  3859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3860. {
  3861. tempIndex = ((gun_index==2) ? 1: 0);
  3862. }
  3863. else
  3864. {
  3865. tempIndex = gun_index;
  3866. }
  3867. for (int index = 0; index < CCS_QUANTITY; index++)
  3868. {
  3869. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3870. {
  3871. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3872. }
  3873. } // END OF FOR CCS_QUANTITY
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3875. }
  3876. else if(gunType[gun_index] == 'G')
  3877. {
  3878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3879. {
  3880. tempIndex = ((gun_index==2) ? 1: 0);
  3881. }
  3882. else
  3883. {
  3884. tempIndex = gun_index;
  3885. }
  3886. for (int index = 0; index < GB_QUANTITY; index++)
  3887. {
  3888. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3889. {
  3890. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3891. }
  3892. } // END OF FOR GB_QUANTITY
  3893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3894. }
  3895. else
  3896. {
  3897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3898. {
  3899. tempIndex = 2;
  3900. }
  3901. else
  3902. {
  3903. tempIndex = gun_index;
  3904. }
  3905. for (int index = 0; index < AC_QUANTITY; index++)
  3906. {
  3907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3908. {
  3909. 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
  3910. }
  3911. } // END OF FOR AC_QUANTITY
  3912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3913. }
  3914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3917. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3920. //SoC
  3921. //idx_sample=5;
  3922. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3923. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3924. {
  3925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3926. {
  3927. tempIndex = ((gun_index==2) ? 1: 0);
  3928. }
  3929. else
  3930. {
  3931. tempIndex = gun_index;
  3932. }
  3933. if(gunType[gun_index] == 'J')
  3934. {
  3935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3936. {
  3937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3938. {
  3939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3940. }
  3941. }
  3942. }
  3943. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3944. {
  3945. for (int index = 0; index < CCS_QUANTITY; index++)
  3946. {
  3947. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3948. {
  3949. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3950. }
  3951. }
  3952. }
  3953. else if(gunType[gun_index] == 'G')
  3954. {
  3955. for (int index = 0; index < GB_QUANTITY; index++)
  3956. {
  3957. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3958. {
  3959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3960. }
  3961. }
  3962. }
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3969. } // END FOR DC CASE
  3970. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3971. {
  3972. 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\"}]}]}]"
  3973. ,gun_index+1
  3974. ,MESSAGE_TYPE_CALL
  3975. ,guid
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3981. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  4024. );
  4025. }
  4026. else
  4027. {
  4028. 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\"}]}]}]"
  4029. ,gun_index+1
  4030. ,MESSAGE_TYPE_CALL
  4031. ,guid
  4032. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4033. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4034. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4036. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4037. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4046. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4047. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4048. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4049. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4050. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4073. );
  4074. }
  4075. #if 1 // for TempStopTransaction
  4076. //Delete TempStopTransaction
  4077. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4078. {
  4079. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4080. }
  4081. #endif
  4082. #if 1
  4083. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4084. if(hashmap_operation(0, guid, tempdata) == 1)
  4085. {
  4086. result = PASS;
  4087. DEBUG_INFO("StopTransaction mapitem pass\n");
  4088. }
  4089. #endif
  4090. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4091. /*
  4092. if(GetTransactionQueueNum() == 1)
  4093. {
  4094. LWS_Send(queuedata+2);
  4095. }*/
  4096. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4097. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4098. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  4099. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4100. {
  4101. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4102. }
  4103. //for test
  4104. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4105. return result;
  4106. }
  4107. int sendMeterValuesRequest(int gun_index)
  4108. {
  4109. mtrace();
  4110. int result = FAIL;
  4111. // char message[1500]={0};
  4112. char guid[37]={0};
  4113. //int idx_sample=0;
  4114. //int length = 0;
  4115. char tempdata[65]={0};
  4116. int tempIndex = 0;
  4117. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4118. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  4119. /*
  4120. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  4121. {
  4122. DEBUG_INFO("NOT SENT METER Vlaue\n");
  4123. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  4124. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  4125. return result;
  4126. }*/
  4127. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4128. {
  4129. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4130. }
  4131. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4132. //set value
  4133. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4134. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4135. random_uuid(guid);
  4136. //UTC Date time
  4137. struct timeval tmnow;
  4138. struct tm *tm;
  4139. char buf[28];//, usec_buf[6];
  4140. gettimeofday(&tmnow, NULL);
  4141. time_t t;
  4142. t = time(NULL);
  4143. /*UTC time and date*/
  4144. tm = gmtime(&t);
  4145. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4147. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4148. //idx_sample=0;
  4149. //********************************(1)Current.Export************************************************/
  4150. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4151. if(gunType[gun_index] == 'J')
  4152. {
  4153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4154. {
  4155. tempIndex = ((gun_index==2) ? 1: 0);
  4156. }
  4157. else
  4158. {
  4159. tempIndex = gun_index;
  4160. }
  4161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4162. {
  4163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4164. {
  4165. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4166. }
  4167. }
  4168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4169. }
  4170. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4171. {
  4172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4173. {
  4174. tempIndex = ((gun_index==2) ? 1: 0);
  4175. }
  4176. else
  4177. {
  4178. tempIndex = gun_index;
  4179. }
  4180. for (int index = 0; index < CCS_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4183. {
  4184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4185. }
  4186. }
  4187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4188. }
  4189. else if(gunType[gun_index] == 'G')
  4190. {
  4191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4192. {
  4193. tempIndex = ((gun_index==2) ? 1: 0);
  4194. }
  4195. else
  4196. {
  4197. tempIndex = gun_index;
  4198. }
  4199. for (int index = 0; index < GB_QUANTITY; index++)
  4200. {
  4201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4202. {
  4203. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4204. }
  4205. }
  4206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4207. }
  4208. else
  4209. {
  4210. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4211. {
  4212. tempIndex = 2;
  4213. }
  4214. else
  4215. {
  4216. tempIndex = gun_index;
  4217. }
  4218. for (int index = 0; index < AC_QUANTITY; index++)
  4219. {
  4220. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4221. {
  4222. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4223. }
  4224. }
  4225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4226. }
  4227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4230. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4233. //idx_sample=1;
  4234. //********************************(2)Energy.Active.Import.Register ************************************************/
  4235. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4236. if(gunType[gun_index] == 'J')
  4237. {
  4238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4239. {
  4240. tempIndex = ((gun_index==2) ? 1: 0);
  4241. }
  4242. else
  4243. {
  4244. tempIndex = gun_index;
  4245. }
  4246. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4247. {
  4248. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4249. {
  4250. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4251. }
  4252. }
  4253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4254. }
  4255. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4256. {
  4257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4258. {
  4259. tempIndex = ((gun_index==2) ? 1: 0);
  4260. }
  4261. else
  4262. {
  4263. tempIndex = gun_index;
  4264. }
  4265. for (int index = 0; index < CCS_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4268. {
  4269. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4270. }
  4271. }
  4272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4273. }
  4274. else if(gunType[gun_index] == 'G')
  4275. {
  4276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4277. {
  4278. tempIndex = ((gun_index==2) ? 1: 0);
  4279. }
  4280. else
  4281. {
  4282. tempIndex = gun_index;
  4283. }
  4284. for (int index = 0; index < GB_QUANTITY; index++)
  4285. {
  4286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4287. {
  4288. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4289. }
  4290. }
  4291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4292. }
  4293. else
  4294. {
  4295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4296. {
  4297. tempIndex = 2;
  4298. }
  4299. else
  4300. {
  4301. tempIndex = gun_index;
  4302. }
  4303. for (int index = 0; index < AC_QUANTITY; index++)
  4304. {
  4305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4306. {
  4307. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4308. }
  4309. }
  4310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4311. }
  4312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4315. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4318. //idx_sample=2;
  4319. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4321. if(gunType[gun_index] == 'J')
  4322. {
  4323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4324. {
  4325. tempIndex = ((gun_index==2) ? 1: 0);
  4326. }
  4327. else
  4328. {
  4329. tempIndex = gun_index;
  4330. }
  4331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4332. {
  4333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4334. {
  4335. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4336. }
  4337. } // END OF FOR CHAdeMO_QUANTITY
  4338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4339. }
  4340. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4341. {
  4342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4343. {
  4344. tempIndex = ((gun_index==2) ? 1: 0);
  4345. }
  4346. else
  4347. {
  4348. tempIndex = gun_index;
  4349. }
  4350. for (int index = 0; index < CCS_QUANTITY; index++)
  4351. {
  4352. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4353. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4354. {
  4355. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4356. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4357. }
  4358. } // END OF CCS_QUANTITY
  4359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4360. }
  4361. else if(gunType[gun_index] == 'G')
  4362. {
  4363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4364. {
  4365. tempIndex = ((gun_index==2) ? 1: 0);
  4366. }
  4367. else
  4368. {
  4369. tempIndex = gun_index;
  4370. }
  4371. for (int index = 0; index < GB_QUANTITY; index++)
  4372. {
  4373. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4374. {
  4375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4376. }
  4377. } // END OF GB_QUANTITY
  4378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4379. }
  4380. else
  4381. {
  4382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4383. {
  4384. tempIndex = 2;
  4385. }
  4386. else
  4387. {
  4388. tempIndex = gun_index;
  4389. }
  4390. for (int index = 0; index < AC_QUANTITY; index++)
  4391. {
  4392. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4393. {
  4394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4395. }
  4396. }
  4397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4398. }
  4399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4402. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4405. //idx_sample=3;
  4406. //********************************(4)Power.Active.Export************************************************/
  4407. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4408. if(gunType[gun_index] == 'J')
  4409. {
  4410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4411. {
  4412. tempIndex = ((gun_index==2) ? 1: 0);
  4413. }
  4414. else
  4415. {
  4416. tempIndex = gun_index;
  4417. }
  4418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4421. {
  4422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4423. }
  4424. } // END OF FOR
  4425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4426. }
  4427. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4428. {
  4429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4430. {
  4431. tempIndex = ((gun_index==2) ? 1: 0);
  4432. }
  4433. else
  4434. {
  4435. tempIndex = gun_index;
  4436. }
  4437. for (int index = 0; index < CCS_QUANTITY; index++)
  4438. {
  4439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4440. {
  4441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4442. }
  4443. }
  4444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4445. }
  4446. else if(gunType[gun_index] == 'G')
  4447. {
  4448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4449. {
  4450. tempIndex = ((gun_index==2) ? 1: 0);
  4451. }
  4452. else
  4453. {
  4454. tempIndex = gun_index;
  4455. }
  4456. for (int index = 0; index < GB_QUANTITY; index++)
  4457. {
  4458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4459. {
  4460. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4461. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4462. }
  4463. }
  4464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4465. }
  4466. else
  4467. {
  4468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4469. {
  4470. tempIndex = 2;
  4471. }
  4472. else
  4473. {
  4474. tempIndex = gun_index;
  4475. }
  4476. for (int index = 0; index < AC_QUANTITY; index++)
  4477. {
  4478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4479. {
  4480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4481. }
  4482. }
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4484. }
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4488. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4491. //idx_sample=4;
  4492. //***********************************************(5)VOLTAGE******************************************************/
  4493. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4494. if(gunType[gun_index] == 'J')
  4495. {
  4496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4497. {
  4498. tempIndex = ((gun_index==2) ? 1: 0);
  4499. }
  4500. else
  4501. {
  4502. tempIndex = gun_index;
  4503. }
  4504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4505. {
  4506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4507. {
  4508. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4509. }
  4510. }
  4511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4512. }
  4513. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4514. {
  4515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4516. {
  4517. tempIndex = ((gun_index==2) ? 1: 0);
  4518. }
  4519. else
  4520. {
  4521. tempIndex = gun_index;
  4522. }
  4523. for (int index = 0; index < CCS_QUANTITY; index++)
  4524. {
  4525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4526. {
  4527. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4528. }
  4529. }
  4530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4531. }
  4532. else if(gunType[gun_index] == 'G')
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4535. {
  4536. tempIndex = ((gun_index==2) ? 1: 0);
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < GB_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4545. {
  4546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4547. }
  4548. }
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4550. }
  4551. else
  4552. {
  4553. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4554. {
  4555. tempIndex = 2;
  4556. }
  4557. else
  4558. {
  4559. tempIndex = gun_index;
  4560. }
  4561. for (int index = 0; index < AC_QUANTITY; index++)
  4562. {
  4563. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4564. {
  4565. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4566. }
  4567. }
  4568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4569. }
  4570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4573. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4576. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4577. {
  4578. //idx_sample=5;
  4579. //sampledValue = NULL;
  4580. //***********************************************(6)SOC******************************************************/
  4581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4582. {
  4583. tempIndex = ((gun_index==2) ? 1: 0);
  4584. }
  4585. else
  4586. {
  4587. tempIndex = gun_index;
  4588. }
  4589. if(gunType[gun_index] == 'J')
  4590. {
  4591. //tempIndex = ((gun_index==2) ? 1: 0);
  4592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4595. {
  4596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4597. }
  4598. }
  4599. }
  4600. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4601. {
  4602. //tempIndex = ((gun_index==2) ? 1: 0);
  4603. for (int index = 0; index < CCS_QUANTITY; index++)
  4604. {
  4605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4606. {
  4607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4608. }
  4609. }
  4610. }
  4611. else if(gunType[gun_index] == 'G')
  4612. {
  4613. //tempIndex = ((gun_index==2) ? 1: 0);
  4614. for (int index = 0; index < GB_QUANTITY; index++)
  4615. {
  4616. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4617. {
  4618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4619. }
  4620. }
  4621. }
  4622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4628. }
  4629. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4630. {
  4631. 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\"}]}]}]"
  4632. ,gun_index + 1
  4633. ,MESSAGE_TYPE_CALL
  4634. ,guid
  4635. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4636. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4637. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4680. );
  4681. }
  4682. else
  4683. {
  4684. 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\"}]}]}]"
  4685. ,gun_index + 1
  4686. ,MESSAGE_TYPE_CALL
  4687. ,guid
  4688. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4689. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4690. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4726. );
  4727. }
  4728. // Put request guid to hash map
  4729. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4730. 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*/)
  4731. {
  4732. result = PASS;
  4733. DEBUG_INFO("MeterValues mapitem pass\n");
  4734. }
  4735. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4736. /*
  4737. if(GetTransactionQueueNum() == 1)
  4738. {
  4739. LWS_Send(queuedata +2);
  4740. }*/
  4741. return result;
  4742. }
  4743. //==========================================
  4744. // send confirm routine
  4745. //==========================================
  4746. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4747. {
  4748. mtrace();
  4749. int result = FAIL;
  4750. char message[100]={0};
  4751. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4753. LWS_Send(message);
  4754. result = TRUE;
  4755. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4756. return result;
  4757. }
  4758. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4759. {
  4760. mtrace();
  4761. int result = FAIL;
  4762. char message[100]={0};
  4763. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4764. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4765. LWS_Send(message);
  4766. result = TRUE;
  4767. return result;
  4768. }
  4769. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4770. {
  4771. mtrace();
  4772. int result = FAIL;
  4773. char message[100]={0};
  4774. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4775. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4776. LWS_Send(message);
  4777. result = TRUE;
  4778. return result;
  4779. }
  4780. int sendClearCacheConfirmation(char *uuid,char *payload)
  4781. {
  4782. mtrace();
  4783. int result = FAIL;
  4784. char message[500]={0};
  4785. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4786. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4787. LWS_Send(message);
  4788. return result;
  4789. }
  4790. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4791. {
  4792. mtrace();
  4793. int result = FAIL;
  4794. char message[500]={0};
  4795. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4796. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4797. LWS_Send(message);
  4798. return result;
  4799. }
  4800. int sendDataTransferConfirmation(char *uuid,char *payload)
  4801. {
  4802. mtrace();
  4803. char statusStr[20]={0};
  4804. char dataStr[10]={0};
  4805. char sstr[20]={0};
  4806. int c = 0;
  4807. char *loc;
  4808. int result = FAIL;
  4809. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4810. /**********************status**************************/
  4811. loc = strstr(payload, "status");
  4812. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4813. c = 0;
  4814. while (loc[3+strlen("status")+c] != '\"')
  4815. {
  4816. sstr[c] = loc[3+strlen("status")+c];
  4817. c++;
  4818. }
  4819. sstr[c] = '\0';
  4820. strcpy(statusStr, sstr);
  4821. /**********************data**************************/
  4822. loc = strstr(payload, "data");
  4823. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4824. c = 0;
  4825. while (loc[3+strlen("data")+c] != '\"')
  4826. {
  4827. sstr[c] = loc[3+strlen("data")+c];
  4828. c++;
  4829. }
  4830. sstr[c] = '\0';
  4831. strcpy(dataStr, sstr);
  4832. return result;
  4833. }
  4834. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4835. {
  4836. mtrace();
  4837. int result = FAIL;
  4838. char message[1000]={0};
  4839. int CompositeScheduleIndex = 0;
  4840. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4841. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4842. if(nPeriod == 0)
  4843. {
  4844. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4845. {
  4846. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4847. ,MESSAGE_TYPE_CALLRESULT
  4848. ,uuid
  4849. ,payload
  4850. ,connectorIdInt);
  4851. }
  4852. else
  4853. {
  4854. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4855. ,MESSAGE_TYPE_CALLRESULT
  4856. ,uuid
  4857. ,payload
  4858. ,connectorIdInt
  4859. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4860. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4861. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4862. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4863. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4864. }
  4865. }
  4866. else
  4867. {
  4868. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4869. ,MESSAGE_TYPE_CALLRESULT
  4870. ,uuid
  4871. ,payload
  4872. ,connectorIdInt
  4873. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4874. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4875. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4876. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4877. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4878. {
  4879. if (idx_sample == 0)
  4880. {
  4881. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4882. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4883. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4884. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4885. }
  4886. else
  4887. {
  4888. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4890. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4891. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4892. }
  4893. }
  4894. sprintf(message + strlen(message), "]}}]");
  4895. }
  4896. LWS_Send(message);
  4897. result = TRUE;
  4898. return result;
  4899. }
  4900. int sendGetConfigurationConfirmation(char *uuid)
  4901. {
  4902. mtrace();
  4903. int result = FAIL;
  4904. int MaxKeySupported = 0;
  4905. int sentConfigurationNumber= 0;
  4906. int sentunConfigurationNumber= 0;
  4907. char message[4000]={0};
  4908. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4909. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4910. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4911. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4912. ,MESSAGE_TYPE_CALLRESULT
  4913. ,uuid );
  4914. //configuration key
  4915. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4916. {
  4917. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4918. {
  4919. if (sentConfigurationNumber == 0)
  4920. {
  4921. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4922. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4923. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4924. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4925. }
  4926. else
  4927. {
  4928. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4929. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4930. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4931. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4932. }
  4933. sentConfigurationNumber = sentConfigurationNumber + 1;
  4934. }
  4935. }
  4936. sprintf(message + strlen(message), "]");
  4937. if(UnknownKeynum != 0)
  4938. {
  4939. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4940. //unkown key
  4941. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4942. {
  4943. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4944. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4945. if(sentunConfigurationNumber == 0)
  4946. {
  4947. sprintf(message + strlen(message), "\"%s\""
  4948. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4949. }
  4950. else
  4951. {
  4952. sprintf(message + strlen(message), ",\"%s\""
  4953. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4954. }
  4955. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4956. }
  4957. sprintf(message + strlen(message), "]");
  4958. }
  4959. sprintf(message + strlen(message), "}]");
  4960. LWS_Send(message);
  4961. return result;
  4962. }
  4963. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4964. {
  4965. mtrace();
  4966. int result = FAIL;
  4967. char message[400]={0};
  4968. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4969. if(strcmp(payload,"")==0)
  4970. {
  4971. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4972. }
  4973. else
  4974. {
  4975. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4976. }
  4977. LWS_Send(message);
  4978. result = TRUE;
  4979. return result;
  4980. }
  4981. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4982. {
  4983. mtrace();
  4984. int result = FAIL;
  4985. char message[80]={0};
  4986. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4987. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4988. LWS_Send(message);
  4989. result = TRUE;
  4990. return result;
  4991. }
  4992. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4993. {
  4994. mtrace();
  4995. int result = FAIL;
  4996. char message[80]={0};
  4997. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4999. LWS_Send(message);
  5000. result = TRUE;
  5001. return result;
  5002. }
  5003. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5004. {
  5005. mtrace();
  5006. int result = FAIL;
  5007. char message[80]={0};
  5008. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5009. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5010. LWS_Send(message);
  5011. result = TRUE;
  5012. return result;
  5013. }
  5014. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5015. {
  5016. mtrace();
  5017. int result = FAIL;
  5018. char message[80]={0};
  5019. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5020. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5021. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5022. LWS_Send(message);
  5023. result = TRUE;
  5024. return result;
  5025. }
  5026. int sendResetConfirmation(char *uuid,char *payload)
  5027. {
  5028. mtrace();
  5029. int result = FAIL;
  5030. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5031. char message[80]={0};
  5032. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5033. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5034. LWS_Send(message);
  5035. result = TRUE;
  5036. return result;
  5037. }
  5038. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5039. {
  5040. mtrace();
  5041. int result = FAIL;
  5042. char message[500]={0};
  5043. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5044. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5045. LWS_Send(message);
  5046. result = TRUE;
  5047. return result;
  5048. }
  5049. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5050. {
  5051. mtrace();
  5052. int result = FAIL;
  5053. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5054. char message[80]={0};
  5055. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5056. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5057. LWS_Send(message);
  5058. result = TRUE;
  5059. return result;
  5060. }
  5061. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5062. {
  5063. mtrace();
  5064. int result = FAIL;
  5065. char message[80]={0};
  5066. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5067. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5068. LWS_Send(message);
  5069. result = TRUE;
  5070. return result;
  5071. }
  5072. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5073. {
  5074. mtrace();
  5075. int result = FAIL;
  5076. char message[80]={0};
  5077. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5078. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5079. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5080. LWS_Send(message);
  5081. result = TRUE;
  5082. return result;
  5083. }
  5084. int sendUpdateFirmwareConfirmation(char *uuid)
  5085. {
  5086. mtrace();
  5087. int result = FAIL;
  5088. char message[60]={0};
  5089. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5090. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5091. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5092. LWS_Send(message);
  5093. result = TRUE;
  5094. return result;
  5095. }
  5096. //==========================================
  5097. // send CallError routine
  5098. //==========================================
  5099. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5100. {
  5101. mtrace();
  5102. char message[220]={0};
  5103. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5104. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5105. LWS_Send(message);
  5106. }
  5107. //==========================================
  5108. // Handle server request routine Start
  5109. //==========================================
  5110. int handleCancelReservationRequest(char *uuid, char *payload)
  5111. {
  5112. mtrace();
  5113. int result = FAIL;
  5114. int gunNO = 0;
  5115. int reservationIdInt =0;
  5116. char comfirmstr[20];
  5117. DEBUG_INFO("handleCancelReservationRequest...\n");
  5118. json_object *CancelReservation;
  5119. CancelReservation = json_tokener_parse(payload);
  5120. if(!is_error(CancelReservation))
  5121. {
  5122. // Required data
  5123. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5124. }
  5125. json_object_put(CancelReservation);
  5126. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5127. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5128. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5129. //check Transaction active
  5130. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5132. {
  5133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5134. {
  5135. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5136. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5137. if(gunType[2] == 'J')
  5138. {
  5139. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5140. }
  5141. else
  5142. {
  5143. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5144. }
  5145. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5146. goto end;
  5147. }
  5148. }
  5149. for (int index = 0; index < CCS_QUANTITY; index++)
  5150. {
  5151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5152. {
  5153. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5154. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5155. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5156. {
  5157. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5158. }
  5159. else
  5160. {
  5161. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5162. }
  5163. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5164. goto end;
  5165. }
  5166. }
  5167. for (int index = 0; index < GB_QUANTITY; index++)
  5168. {
  5169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5170. {
  5171. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5172. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5173. if(gunType[2] == 'G')
  5174. {
  5175. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5176. }
  5177. else
  5178. {
  5179. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5180. }
  5181. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5182. goto end;
  5183. }
  5184. }
  5185. for (int index = 0; index < AC_QUANTITY; index++)
  5186. {
  5187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5188. {
  5189. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5190. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5191. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5192. {
  5193. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5194. }
  5195. else
  5196. {
  5197. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5198. }
  5199. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5200. goto end;
  5201. }
  5202. }
  5203. //The reservationId does NOT match the reservationId
  5204. sendCancelReservationConfirmation(uuid, comfirmstr);
  5205. end:
  5206. // Fill in ocpp packet uuid
  5207. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5208. return result;
  5209. }
  5210. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5211. {
  5212. mtrace();
  5213. int result = FAIL;
  5214. int gunIndex = 0;
  5215. char typeStr[16]={0};
  5216. char comfirmstr[20];
  5217. int specificId = FALSE;
  5218. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5219. json_object *ChangeAvailability;
  5220. ChangeAvailability = json_tokener_parse(payload);
  5221. if(!is_error(ChangeAvailability))
  5222. {
  5223. // Required data
  5224. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5225. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5226. }
  5227. json_object_put(ChangeAvailability);
  5228. if(gunIndex != 0)
  5229. {
  5230. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5231. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5232. }
  5233. else
  5234. {
  5235. for(int i=0; i < gunTotalNumber; i++)
  5236. {
  5237. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5238. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5239. }
  5240. }
  5241. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5243. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5244. {
  5245. specificId = TRUE;
  5246. }
  5247. if(specificId == FALSE)
  5248. goto end;
  5249. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5250. {
  5251. //----------------------gunIndex is 0 ------------------------------------------------//
  5252. if(gunIndex == 0)
  5253. {
  5254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5255. {
  5256. for(int i=0; i < gunTotalNumber; i++)
  5257. {
  5258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5259. {
  5260. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5261. {
  5262. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5263. {
  5264. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5265. goto end;
  5266. }
  5267. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5270. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5271. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5272. {
  5273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5274. goto end;
  5275. }
  5276. }
  5277. }//END FOR CHAdeMO_QUANTITY
  5278. for (int index = 0; index < CCS_QUANTITY; index++)
  5279. {
  5280. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5281. {
  5282. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5283. {
  5284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5285. goto end;
  5286. }
  5287. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5288. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5289. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5290. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5291. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5292. {
  5293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5294. goto end;
  5295. }
  5296. }
  5297. }//END FOR CCS_QUANTITY
  5298. for (int index = 0; index < GB_QUANTITY; index++)
  5299. {
  5300. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5301. {
  5302. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5303. {
  5304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5305. goto end;
  5306. }
  5307. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5308. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5310. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5311. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5312. {
  5313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5314. goto end;
  5315. }
  5316. }
  5317. }// END FOR GB_QUANTITY
  5318. for (int index = 0; index < AC_QUANTITY; index++)
  5319. {
  5320. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5321. {
  5322. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5323. {
  5324. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5325. goto end;
  5326. }
  5327. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5328. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5329. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5330. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5331. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5332. {
  5333. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5334. goto end;
  5335. }
  5336. }
  5337. }//END FOR AC_QUANTITY
  5338. }// END FOR gunTotalNumber
  5339. }
  5340. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5341. {
  5342. for(int i=0; i < gunTotalNumber; i++)
  5343. {
  5344. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5345. {
  5346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5347. goto end;
  5348. }
  5349. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5350. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5351. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5352. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5353. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5354. {
  5355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5356. goto end;
  5357. }
  5358. }
  5359. }
  5360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5361. goto end;
  5362. }
  5363. //----------------------gunIndex is not 0 ------------------------------------------------//
  5364. //check Transaction active
  5365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5366. {
  5367. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5368. {
  5369. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5370. {
  5371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5372. goto end;
  5373. }
  5374. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5379. {
  5380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5381. goto end;
  5382. }
  5383. else
  5384. {
  5385. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5387. goto end;
  5388. }
  5389. }
  5390. }//END FOR CHAdeMO_QUANTITY
  5391. for (int index = 0; index < CCS_QUANTITY; index++)
  5392. {
  5393. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5394. {
  5395. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5396. {
  5397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5398. goto end;
  5399. }
  5400. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5401. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5403. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5405. {
  5406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5407. goto end;
  5408. }
  5409. else
  5410. {
  5411. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5413. goto end;
  5414. }
  5415. }
  5416. }//END FOR CCS_QUANTITY
  5417. for (int index = 0; index < GB_QUANTITY; index++)
  5418. {
  5419. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5420. {
  5421. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5422. {
  5423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5424. goto end;
  5425. }
  5426. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5427. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5431. {
  5432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5433. goto end;
  5434. }
  5435. else
  5436. {
  5437. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5439. goto end;
  5440. }
  5441. }
  5442. }// END FOR GB_QUANTITY
  5443. for (int index = 0; index < AC_QUANTITY; index++)
  5444. {
  5445. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5446. {
  5447. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5448. {
  5449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5450. goto end;
  5451. }
  5452. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5457. {
  5458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5459. goto end;
  5460. }
  5461. else
  5462. {
  5463. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5465. goto end;
  5466. }
  5467. }
  5468. }//END FOR AC_QUANTITY
  5469. }//END FOR AvailabilityTypeStr[Inoperative]
  5470. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5471. {
  5472. //----------------------gunIndex is 0 ------------------------------------------------//
  5473. if(gunIndex == 0)
  5474. {
  5475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5476. {
  5477. for(int i=0; i < gunTotalNumber; i++)
  5478. {
  5479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5480. {
  5481. 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
  5482. {
  5483. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5484. goto end;
  5485. }
  5486. }//END FOR CHAdeMO_QUANTITY
  5487. for (int index = 0; index < CCS_QUANTITY; index++)
  5488. {
  5489. 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
  5490. {
  5491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5492. goto end;
  5493. }
  5494. }//END FOR CCS_QUANTITY
  5495. for (int index = 0; index < GB_QUANTITY; index++)
  5496. {
  5497. 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
  5498. {
  5499. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5501. goto end;
  5502. }
  5503. }// END FOR GB_QUANTITY
  5504. for (int index = 0; index < AC_QUANTITY; index++)
  5505. {
  5506. 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
  5507. {
  5508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5509. goto end;
  5510. }
  5511. }//END FOR CHAdeMO_QUANTITY
  5512. }// END FOR gunTotalNumber
  5513. }
  5514. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5515. {
  5516. for(int i=0; i < gunTotalNumber; i++)
  5517. {
  5518. for (int index = 0; index < AC_QUANTITY; index++)
  5519. {
  5520. 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
  5521. {
  5522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5523. goto end;
  5524. }
  5525. }//END FOR CHAdeMO_QUANTITY
  5526. } // END FOR gunTotalNumber
  5527. }
  5528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5529. goto end;
  5530. }
  5531. //----------------------gunIndex is not 0 ------------------------------------------------//
  5532. //check Transaction active
  5533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5534. {
  5535. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5536. {
  5537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5538. goto end;
  5539. }
  5540. }//END FOR CHAdeMO_QUANTITY
  5541. for (int index = 0; index < CCS_QUANTITY; index++)
  5542. {
  5543. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5544. {
  5545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5546. goto end;
  5547. }
  5548. }//END FOR CCS_QUANTITY
  5549. for (int index = 0; index < GB_QUANTITY; index++)
  5550. {
  5551. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5552. {
  5553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5554. goto end;
  5555. }
  5556. }// END FOR GB_QUANTITY
  5557. for (int index = 0; index < AC_QUANTITY; index++)
  5558. {
  5559. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5560. {
  5561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5562. goto end;
  5563. }
  5564. }//END FOR AC_QUANTITY
  5565. }//END FOR AvailabilityTypeStr[Operative]
  5566. end:
  5567. if(gunIndex != 0)
  5568. {
  5569. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5570. }
  5571. else
  5572. {
  5573. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5574. }
  5575. if(gunIndex != 0)
  5576. {
  5577. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5578. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5579. }
  5580. else
  5581. {
  5582. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5583. {
  5584. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5585. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5586. }
  5587. }
  5588. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5589. return result;
  5590. }
  5591. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5592. {
  5593. mtrace();
  5594. int result = FAIL;
  5595. char keystr[40]={0};
  5596. char valuestr[100]={0};
  5597. char comfirmstr[20]={0};
  5598. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5599. json_object *ChangeConfiguration;
  5600. ChangeConfiguration = json_tokener_parse(payload);
  5601. if(!is_error(ChangeConfiguration))
  5602. {
  5603. // Required data
  5604. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5605. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5606. }
  5607. json_object_put(ChangeConfiguration);
  5608. if((uuid==NULL) || (payload ==NULL) )
  5609. {
  5610. DEBUG_ERROR("Payload is null\n");
  5611. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5612. }
  5613. else
  5614. {
  5615. int status = setKeyValue(keystr, valuestr);
  5616. switch(status)
  5617. {
  5618. case ConfigurationStatus_Accepted:
  5619. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5620. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5621. StoreConfigurationTable();
  5622. break;
  5623. case ConfigurationStatus_Rejected:
  5624. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5625. break;
  5626. case RebootRequired:
  5627. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5628. StoreConfigurationTable();
  5629. break;
  5630. case NotSupported:
  5631. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5632. break;
  5633. default:
  5634. break;
  5635. }
  5636. }
  5637. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5638. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5639. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5640. {
  5641. ChageWebSocketPingInterval(atoi(valuestr));
  5642. }
  5643. return result;
  5644. }
  5645. int handleClearCacheRequest(char *uuid, char *payload)
  5646. {
  5647. mtrace();
  5648. int result = FAIL;
  5649. char comfirmstr[20];
  5650. int fd;
  5651. char rmFileCmd[100]={0};
  5652. struct stat stats;
  5653. DEBUG_INFO("handleClearCacheRequest...\n");
  5654. stat("/Storage/OCPP", &stats);
  5655. // Check for directory existence
  5656. if (S_ISDIR(stats.st_mode) == 1)
  5657. {}
  5658. else
  5659. {
  5660. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5661. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5662. system(rmFileCmd);
  5663. }
  5664. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5665. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5666. {
  5667. DEBUG_INFO("AuthorizationCache file exist.\n");
  5668. }
  5669. else
  5670. {
  5671. DEBUG_INFO("AuthorizationCache file not exist\n");
  5672. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5673. if(log == NULL)
  5674. {
  5675. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5676. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5677. goto end;
  5678. }
  5679. else
  5680. {
  5681. fclose(log);
  5682. }
  5683. }
  5684. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5685. {
  5686. DEBUG_INFO("open AuthorizationCache file failed\n");
  5687. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5688. }
  5689. else
  5690. {
  5691. DEBUG_INFO("open AuthorizationCache file successful\n");
  5692. ftruncate(fd,0);
  5693. lseek(fd,0,SEEK_SET);
  5694. close(fd);
  5695. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5696. }
  5697. end:
  5698. sendClearCacheConfirmation(uuid, comfirmstr);
  5699. return result;
  5700. }
  5701. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5702. {
  5703. mtrace();
  5704. int result = FAIL;
  5705. int resultRename;
  5706. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5707. char chargingProfilePurposeStr[26]={0};
  5708. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5709. char tempchargingProfilePurposeStr[26]={0};
  5710. char sstr[160]={0};
  5711. char str[100]={0};
  5712. int c = 0;
  5713. char *loc;
  5714. char fname[200]={0};
  5715. char comfirmstr[20]={0};
  5716. char word[1600]={0};
  5717. int clearflag = FALSE;
  5718. int chargingProfileIdIsNULL = FALSE;
  5719. int connectorIsNULL = FALSE;
  5720. int chargingProfilePurposeIsNULL = FALSE;
  5721. int stackLevelIsNULL = FALSE;
  5722. //int GotoEnd = FALSE;
  5723. FILE *fptr1, *fptr2;
  5724. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5725. int n_chargingProfile=0;
  5726. int isEmptyFile = FALSE;
  5727. char sLineWord[1600]={0};
  5728. char chargingProfiles[10][100]={0};
  5729. int ChargeProfileCount = 0;
  5730. char ch;
  5731. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5732. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5733. json_object *ClearChargingProfile;
  5734. ClearChargingProfile = json_tokener_parse(payload);
  5735. if(!is_error(ClearChargingProfile))
  5736. {
  5737. // Optional data
  5738. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5739. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5740. else
  5741. chargingProfileIdIsNULL = TRUE;
  5742. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5743. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5744. else
  5745. connectorIsNULL = TRUE;
  5746. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5747. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5748. else
  5749. chargingProfilePurposeIsNULL = TRUE;
  5750. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5751. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5752. else
  5753. stackLevelIsNULL = TRUE;
  5754. }
  5755. json_object_put(ClearChargingProfile);
  5756. if(connectorIsNULL == FALSE)
  5757. {
  5758. switch(connectorIdInt)
  5759. {
  5760. case 0:
  5761. if(chargingProfilePurposeIsNULL == TRUE)
  5762. {
  5763. int l = 0;
  5764. strcpy(fname, ChargePointMaxProfile_JSON);
  5765. if((access(fname,F_OK))!=-1)
  5766. {
  5767. strcpy(chargingProfiles[l], fname);
  5768. l = l + 1;
  5769. }
  5770. strcpy(fname, TxDefaultProfile_0_JSON);
  5771. if((access(fname,F_OK))!=-1)
  5772. {
  5773. strcpy(chargingProfiles[l], fname);
  5774. l = l + 1;
  5775. }
  5776. ChargeProfileCount = l;
  5777. }
  5778. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5779. {
  5780. strcpy(fname, ChargePointMaxProfile_JSON);
  5781. if((access(fname,F_OK))!=-1)
  5782. {
  5783. strcpy(chargingProfiles[0], fname);
  5784. ChargeProfileCount = 1;
  5785. }
  5786. }
  5787. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5788. {
  5789. strcpy(fname, TxDefaultProfile_0_JSON);
  5790. if((access(fname,F_OK))!=-1)
  5791. {
  5792. strcpy(chargingProfiles[0], fname);
  5793. ChargeProfileCount = 1;
  5794. }
  5795. }
  5796. break;
  5797. default:
  5798. if(chargingProfilePurposeIsNULL == TRUE)
  5799. {
  5800. int m = 0;
  5801. memset(fname, 0, ARRAY_SIZE(fname));
  5802. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5803. if((access(fname,F_OK))!=-1)
  5804. {
  5805. strcpy(chargingProfiles[m], fname);
  5806. m = m + 1;
  5807. }
  5808. memset(fname, 0, ARRAY_SIZE(fname));
  5809. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5810. if((access(fname,F_OK))!=-1)
  5811. {
  5812. strcpy(chargingProfiles[m], fname);
  5813. m = m + 1;
  5814. }
  5815. ChargeProfileCount = m;
  5816. }
  5817. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5818. {
  5819. //strcpy(fname, TxDefaultProfile_1_JSON);
  5820. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5821. if((access(fname,F_OK))!=-1)
  5822. {
  5823. strcpy(chargingProfiles[0], fname);
  5824. ChargeProfileCount = 1;
  5825. }
  5826. }
  5827. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5828. {
  5829. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5830. if((access(fname,F_OK))!=-1)
  5831. {
  5832. strcpy(chargingProfiles[0], fname);
  5833. ChargeProfileCount = 1;
  5834. }
  5835. //strcpy(fname, TxProfile_1_JSON);
  5836. }
  5837. //strcpy(fname, ChargePointMaxProfile_JSON );
  5838. break;
  5839. }
  5840. }
  5841. else // Check all Charging Profiles
  5842. {
  5843. int i = 0;
  5844. char fnametemp[200]={0};
  5845. ChargeProfileCount = 0;
  5846. //Check ChargePointMaxProfile.json exit
  5847. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5848. {
  5849. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5850. i = i + 1;
  5851. }
  5852. //Check TxDefaultProfile_0.json exit
  5853. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5854. {
  5855. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5856. i = i + 1;
  5857. }
  5858. //Check TxDefaultProfile_%d.json
  5859. for(int j=1; j <= gunTotalNumber; j++)
  5860. {
  5861. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5862. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5863. if((access(fnametemp,F_OK))!=-1)
  5864. {
  5865. strcpy(chargingProfiles[i], fnametemp);
  5866. i = i + 1;
  5867. }
  5868. }
  5869. //Check TxProfile_%d.json
  5870. for(int j=1; j <= gunTotalNumber; j++)
  5871. {
  5872. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5873. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5874. if((access(fnametemp,F_OK))!=-1)
  5875. {
  5876. strcpy(chargingProfiles[i], fnametemp);
  5877. i = i + 1;
  5878. }
  5879. }
  5880. ChargeProfileCount = i;
  5881. }// End connectorIsNULL is TRUE
  5882. if(ChargeProfileCount == 0)
  5883. {
  5884. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5885. goto end;
  5886. }
  5887. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5888. {
  5889. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5890. goto end;
  5891. }
  5892. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5893. {
  5894. memset(str, 0, ARRAY_SIZE(str));
  5895. // clear temp file
  5896. sprintf(str,"rm -f %s",temp);
  5897. system(str);
  5898. for(int k=0; k < ChargeProfileCount; k++)
  5899. {
  5900. memset(str, 0, ARRAY_SIZE(str));
  5901. //clear file in C
  5902. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5903. system(str);
  5904. }
  5905. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5906. goto end;
  5907. }
  5908. else if(connectorIsNULL == TRUE)
  5909. {
  5910. for(int k=0; k < ChargeProfileCount; k++)
  5911. {
  5912. fptr1 = fopen(chargingProfiles[k], "r");
  5913. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5914. //Check Charging Profile Count
  5915. while(fscanf(fptr1, "%s", word) != EOF)
  5916. {
  5917. //DEBUG_INFO("word=%s\n",word);
  5918. if(strstr(word, "chargingProfileId")!= NULL)
  5919. {
  5920. //DEBUG_INFO("test chargingProfileId \n");
  5921. n_chargingProfile = n_chargingProfile + 1;
  5922. //DEBUG_INFO("chargingProfileId Found\n");
  5923. }
  5924. }
  5925. rewind(fptr1);
  5926. //search Charging Profile Element
  5927. //int i= 0;
  5928. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5929. {
  5930. //------------------------tempconnectorIdInt------------------------//
  5931. loc = strstr(sLineWord, "connectorId");
  5932. c = 0;
  5933. memset(sstr ,0, sizeof(sstr) );
  5934. while (loc[strlen("connectorId")+2+c] != ',')
  5935. {
  5936. sstr[c] = loc[strlen("connectorId")+2+c];
  5937. c++;
  5938. }
  5939. sstr[c] = '\0';
  5940. tempconnectorIdInt = atoi(sstr);
  5941. printf("file's gun number is %d\n", tempconnectorIdInt);
  5942. //--------------------------chargingProfileId--------------------//
  5943. c = 0;
  5944. loc = strstr(sLineWord, "chargingProfileId");
  5945. memset(sstr ,0, ARRAY_SIZE(sstr));
  5946. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5947. {
  5948. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5950. c++;
  5951. }
  5952. sstr[c] = '\0';
  5953. tempchargingProfileIdInt = atoi(sstr);
  5954. //stackLevel
  5955. c = 0;
  5956. loc = strstr(sLineWord, "stackLevel");
  5957. memset(sstr ,0, ARRAY_SIZE(sstr));
  5958. while (loc[strlen("stackLevel")+2+c] != ',')
  5959. {
  5960. sstr[c] = loc[strlen("stackLevel")+2+c];
  5961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5962. c++;
  5963. }
  5964. sstr[c] = '\0';
  5965. tempstackLevelInt = atoi(sstr);
  5966. c = 0;
  5967. loc = strstr(sLineWord, "chargingProfilePurpose");
  5968. memset(sstr ,0, ARRAY_SIZE(sstr));
  5969. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5970. {
  5971. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5972. c++;
  5973. }
  5974. sstr[c] = '\0';
  5975. strcpy(tempchargingProfilePurposeStr, sstr);
  5976. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5977. {
  5978. //------- not write to fptr2-------//
  5979. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5980. //clearflag = TRUE;
  5981. }
  5982. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5983. {
  5984. //------- not write to fptr2-------//
  5985. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5986. }
  5987. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5988. {
  5989. //------- not write to fptr2-------//
  5990. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5991. }
  5992. else
  5993. {
  5994. fprintf(fptr2, sLineWord);//writing data into file
  5995. }
  5996. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5997. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5998. if(clearflag == TRUE)
  5999. {
  6000. fclose(fptr1);
  6001. fclose(fptr2);
  6002. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6003. system(str);
  6004. // clear temp file
  6005. sprintf(str,"rm -f %s",temp);
  6006. system(str);
  6007. }
  6008. else
  6009. {
  6010. fclose(fptr1);
  6011. fclose(fptr2);
  6012. memset(str, 0, ARRAY_SIZE(str));
  6013. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6014. system(str);
  6015. resultRename = rename(temp, chargingProfiles[k]);
  6016. if(resultRename == 0)
  6017. {
  6018. DEBUG_INFO("File ChargingProfile renamed successfully");
  6019. }
  6020. else
  6021. {
  6022. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6023. }
  6024. if(comfirmstr[0]== 0)
  6025. {
  6026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6027. }
  6028. //Check chargingProfile is empty file
  6029. /*------ Read the file ----------------*/
  6030. fptr1=fopen(chargingProfiles[k],"r");
  6031. ch=fgetc(fptr1);
  6032. rewind(fptr1);
  6033. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6034. if(ch!=EOF)
  6035. {
  6036. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6037. {
  6038. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6039. if(sLineWord[0]=='\0')
  6040. {
  6041. isEmptyFile = TRUE;
  6042. break;
  6043. }
  6044. else
  6045. {
  6046. isEmptyFile = FALSE;
  6047. break;
  6048. }
  6049. }
  6050. }
  6051. fclose(fptr1);
  6052. if(isEmptyFile == TRUE)
  6053. {
  6054. memset(str, 0, ARRAY_SIZE(str));
  6055. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6056. system(str);
  6057. }
  6058. }
  6059. }// End of while(int k=0; k < ChargePointCount; k++)
  6060. }
  6061. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6062. {
  6063. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6064. for(int k=0; k < ChargeProfileCount; k++)
  6065. {
  6066. fptr1 = fopen(chargingProfiles[k], "r");
  6067. fptr2 = fopen(temp, "w+");
  6068. //Check Charging Profile Count
  6069. while(fscanf(fptr1, "%s", word) != EOF)
  6070. {
  6071. //DEBUG_INFO("word=%s\n",word);
  6072. if(strstr(word, "chargingProfileId")!= NULL)
  6073. {
  6074. n_chargingProfile = n_chargingProfile + 1;
  6075. }
  6076. }
  6077. rewind(fptr1);
  6078. //search Charging Profile Element
  6079. //int i= 0;
  6080. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6081. {
  6082. //*************************tempconnectorIdInt*********************************/
  6083. loc = strstr(sLineWord, "connectorId");
  6084. c = 0;
  6085. memset(sstr ,0, ARRAY_SIZE(sstr));
  6086. while (loc[strlen("connectorId")+2+c] != ',')
  6087. {
  6088. sstr[c] = loc[strlen("connectorId")+2+c];
  6089. c++;
  6090. }
  6091. sstr[c] = '\0';
  6092. tempconnectorIdInt = atoi(sstr);
  6093. //chargingProfileId
  6094. c = 0;
  6095. loc = strstr(sLineWord, "chargingProfileId");
  6096. memset(sstr ,0, ARRAY_SIZE(sstr));
  6097. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6098. {
  6099. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6100. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6101. c++;
  6102. }
  6103. sstr[c] = '\0';
  6104. tempchargingProfileIdInt = atoi(sstr);
  6105. //stackLevel
  6106. c = 0;
  6107. loc = strstr(sLineWord, "stackLevel");
  6108. memset(sstr ,0, ARRAY_SIZE(sstr));
  6109. while (loc[strlen("stackLevel")+2+c] != ',')
  6110. {
  6111. sstr[c] = loc[strlen("stackLevel")+2+c];
  6112. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6113. c++;
  6114. }
  6115. sstr[c] = '\0';
  6116. tempstackLevelInt = atoi(sstr);
  6117. c = 0;
  6118. loc = strstr(sLineWord, "chargingProfilePurpose");
  6119. memset(sstr ,0, ARRAY_SIZE(sstr));
  6120. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6121. {
  6122. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6123. c++;
  6124. }
  6125. sstr[c] = '\0';
  6126. strcpy(tempchargingProfilePurposeStr, sstr);
  6127. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6128. {
  6129. //------- not write to fptr2-------//
  6130. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6131. //clearflag = TRUE;
  6132. }
  6133. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6134. {
  6135. //------- not write to fptr2-------//
  6136. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6137. }
  6138. else if(stackLevelIsNULL == TRUE)
  6139. {
  6140. //Clear Whole File
  6141. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6142. clearflag = TRUE;
  6143. break;
  6144. }
  6145. else
  6146. {
  6147. fprintf(fptr2, sLineWord);//writing data into file
  6148. }
  6149. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6150. }
  6151. if(clearflag == TRUE)
  6152. {
  6153. fclose(fptr1);
  6154. fclose(fptr2);
  6155. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6156. system(str);
  6157. // clear temp file
  6158. sprintf(str,"rm -f %s",temp);
  6159. system(str);
  6160. }
  6161. else
  6162. {
  6163. fclose(fptr1);
  6164. fclose(fptr2);
  6165. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6166. system(str);
  6167. resultRename = rename(temp, chargingProfiles[k]);
  6168. if(resultRename == 0)
  6169. {
  6170. DEBUG_INFO("File ChargingProfile renamed successfully");
  6171. }
  6172. else
  6173. {
  6174. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6175. }
  6176. if(comfirmstr[0]== 0)
  6177. {
  6178. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6179. }
  6180. //Check chargingProfile is empty file
  6181. /*------ Read the file ----------------*/
  6182. fptr1=fopen(chargingProfiles[k],"r");
  6183. ch=fgetc(fptr1);
  6184. rewind(fptr1);
  6185. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6186. if(ch!=EOF)
  6187. {
  6188. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6189. {
  6190. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6191. if(sLineWord[0]=='\0')
  6192. {
  6193. isEmptyFile = TRUE;
  6194. break;
  6195. }
  6196. else
  6197. {
  6198. isEmptyFile = FALSE;
  6199. break;
  6200. }
  6201. }
  6202. }
  6203. fclose(fptr1);
  6204. if(isEmptyFile == TRUE)
  6205. {
  6206. memset(str, 0, ARRAY_SIZE(str));
  6207. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6208. system(str);
  6209. }
  6210. /*------- End of reading ---------------*/
  6211. }
  6212. } // while(int k=0; k < ChargeProfileCount; k++)
  6213. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6214. end:
  6215. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6216. return result;
  6217. }
  6218. void createFirmwareVersionByDataTransfer(void)
  6219. {
  6220. json_object *FirmwareDataTransfer = json_object_new_object();
  6221. // AC & DC model
  6222. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6223. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6224. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6225. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6226. // DC model
  6227. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6228. {
  6229. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6230. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6231. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6232. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6233. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6234. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6235. }
  6236. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6237. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6238. {
  6239. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6240. }
  6241. // 4G model
  6242. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6243. {
  6244. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6245. }
  6246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6248. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6249. }
  6250. int handleDataTransferRequest(char *uuid, char *payload)
  6251. {
  6252. mtrace();
  6253. json_object *response = json_object_new_object();
  6254. int result = FAIL;
  6255. char tempvendorId[255]={0};
  6256. char tempmessageId[50]={0};
  6257. char tempdata[50]={0};
  6258. char message[2048]={0};
  6259. DEBUG_INFO("handleDataTransferRequest...\n");
  6260. if((uuid != NULL) && (payload != NULL))
  6261. {
  6262. json_object *DataTransfer;
  6263. DataTransfer = json_tokener_parse(payload);
  6264. if(!is_error(DataTransfer))
  6265. {
  6266. // Required data
  6267. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6268. // Optional data
  6269. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6270. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6271. if(json_object_object_get(DataTransfer, "data") != NULL)
  6272. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6273. result = PASS;
  6274. }
  6275. json_object_put(DataTransfer);
  6276. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6277. {
  6278. // Send all moudle firmware version on EVSE
  6279. system("/usr/bin/run_tmate_restart.sh");
  6280. createFirmwareVersionByDataTransfer();
  6281. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6282. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6283. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6284. }
  6285. else
  6286. {
  6287. // Can not find valid message id
  6288. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6289. }
  6290. }
  6291. else
  6292. {
  6293. // Payload is null
  6294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6295. }
  6296. LWS_Send(message);
  6297. return result;
  6298. }
  6299. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6300. {
  6301. mtrace();
  6302. int result = FAIL;
  6303. int connectorIdInt, durationInt;
  6304. char chargingRateUnitStr[4]={0};
  6305. char comfirmstr[20];
  6306. int confirmPeriods = 0;
  6307. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6308. json_object *GetCompositeSchedule;
  6309. GetCompositeSchedule = json_tokener_parse(payload);
  6310. if(!is_error(GetCompositeSchedule))
  6311. {
  6312. // Required data
  6313. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6314. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6315. // Optional data
  6316. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6317. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6318. }
  6319. json_object_put(GetCompositeSchedule);
  6320. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6321. if((connectorIdInt == 0) ||
  6322. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6323. {
  6324. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6325. struct StructChargingProfile tmpProfile[1];
  6326. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6327. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6328. {
  6329. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6330. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6331. }
  6332. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6333. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6334. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6335. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6336. {
  6337. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6338. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6339. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6340. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6341. {
  6342. confirmPeriods = idx;
  6343. break;
  6344. }
  6345. }
  6346. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6347. }
  6348. else
  6349. {
  6350. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6351. }
  6352. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6353. return result;
  6354. }
  6355. int handleGetConfigurationRequest(char *uuid, char *payload)
  6356. {
  6357. mtrace();
  6358. int result = FAIL;
  6359. int MaxKeySupported = 0;
  6360. int n_keys = 0;
  6361. char requestKey[43][50]={0};
  6362. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6363. json_object *GetConfiguration;
  6364. GetConfiguration = json_tokener_parse(payload);
  6365. if(!is_error(GetConfiguration))
  6366. {
  6367. // Optional data
  6368. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6369. {
  6370. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6371. {
  6372. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6373. n_keys = idx + 1;
  6374. }
  6375. }
  6376. }
  6377. json_object_put(GetConfiguration);
  6378. UnknownKeynum = 0;
  6379. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6380. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6381. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6382. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6383. if(n_keys != 0)
  6384. {
  6385. for(int i=0;i<n_keys;i++)
  6386. {
  6387. getKeyValue(requestKey[i]);
  6388. }
  6389. }
  6390. else
  6391. {
  6392. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6393. getKeyValue("");
  6394. }
  6395. processUnkownKey();
  6396. sendGetConfigurationConfirmation(uuid);
  6397. return result;
  6398. }
  6399. static char fnamePlusPath[100]={0};
  6400. static char fnamePWithNoPath[60]={0};
  6401. void checkUploadLog(void)
  6402. {
  6403. FILE *fp;
  6404. /* Open the command for reading. */
  6405. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6406. if (fp == NULL) {
  6407. printf("Failed to run command\n" );
  6408. exit(1);
  6409. }
  6410. int ftppathlen = 0;
  6411. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6412. int i = 0;
  6413. /* Read the output a line at a time - output it. */
  6414. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6415. if(i==0)
  6416. {
  6417. ftppathlen = strlen(fnamePlusPath);
  6418. printf("%s\n", fnamePlusPath);
  6419. fnamePlusPath[ftppathlen]='\0';
  6420. break;
  6421. }
  6422. i= i+1;
  6423. }
  6424. /* close */
  6425. pclose(fp);
  6426. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6427. {
  6428. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6429. {
  6430. fnamePlusPath[k]='\0';
  6431. }
  6432. }
  6433. i=1;
  6434. //char fname[60]={0};
  6435. while(i < ftppathlen)
  6436. {
  6437. int len=ftppathlen-i;
  6438. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6439. {
  6440. printf("compare '/' all right\n");
  6441. break;
  6442. }
  6443. i=i+1;
  6444. }
  6445. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6446. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6447. fnamePWithNoPath[i+1] = '\0';
  6448. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6449. {
  6450. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6451. {
  6452. fnamePWithNoPath[j]='\0';
  6453. }
  6454. }
  6455. FILE* fp1 = fopen(fnamePlusPath, "r");
  6456. if (fp1)
  6457. {
  6458. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6459. // file exists
  6460. fclose(fp1);
  6461. }
  6462. else
  6463. {
  6464. // file doesn't exist
  6465. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6466. }
  6467. }
  6468. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6469. {
  6470. mtrace();
  6471. int result = FAIL;
  6472. char cmdBuf[512];
  6473. char fName[258];
  6474. time_t CurrentTime;
  6475. struct tm *tm;
  6476. system("/usr/bin/run_tmate_restart.sh");
  6477. pthread_t th_Status;
  6478. CurrentTime = time(NULL);
  6479. tm = localtime(&CurrentTime);
  6480. 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);
  6481. sendGetDiagnosticsConfirmation(uuid, fName);
  6482. system("exec /root/logPackTools 'log' 6");
  6483. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6484. system(cmdBuf);
  6485. checkUploadLog();
  6486. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6487. return result;
  6488. }
  6489. void* GetDiagnosticsProcess(void* data)
  6490. {
  6491. pthread_detach(pthread_self());
  6492. mtrace();
  6493. int retriesInt=0, retryIntervalInt=0;
  6494. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6495. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6496. 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};
  6497. int port=0;
  6498. char sstr[260]={ 0 };
  6499. int c = 0;
  6500. char *loc;
  6501. int isSuccess = FALSE;
  6502. char ftpbuf[200]={0};
  6503. char * pch;
  6504. char str[300]={ 0 };
  6505. strcpy(str,(const char*)data);
  6506. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6507. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6508. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6509. //****************location*******************/
  6510. c = 0;
  6511. memset(sstr ,0, ARRAY_SIZE(sstr));
  6512. loc = strstr(str, "location");
  6513. while (loc[3+strlen("location")+c] != '\"')
  6514. {
  6515. sstr[c] = loc[3+strlen("location")+c];
  6516. c++;
  6517. }
  6518. sstr[c] = '\0';
  6519. strcpy(locationstr,sstr);
  6520. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6521. if(strcmp(locationstr,"")==0)
  6522. {
  6523. DEBUG_INFO("location is <Empty>!\n");
  6524. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6525. goto end;
  6526. }
  6527. //****************retries*******************/
  6528. c = 0;
  6529. loc = strstr(str, "retries");
  6530. if(loc == NULL)
  6531. {
  6532. retriesIsNULL = TRUE;
  6533. }
  6534. else
  6535. {
  6536. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6537. {
  6538. sstr[c] = loc[strlen("retries")+2+c];
  6539. c++;
  6540. }
  6541. sstr[c] = '\0';
  6542. retriesInt = atoi(sstr);
  6543. }
  6544. if(retriesIsNULL == TRUE)
  6545. {
  6546. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6547. }
  6548. //****************retryInterval*******************/
  6549. c = 0;
  6550. loc = strstr(str, "retryInterval");
  6551. if(loc == NULL)
  6552. {
  6553. retryIntervalIsNULL = TRUE;
  6554. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6555. }
  6556. else
  6557. {
  6558. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6559. {
  6560. sstr[c] = loc[strlen("retryInterval")+2+c];
  6561. c++;
  6562. }
  6563. sstr[c] = '\0';
  6564. retryIntervalInt = atoi(sstr);
  6565. }
  6566. //****************startTime*******************/
  6567. c = 0;
  6568. memset(sstr ,0, ARRAY_SIZE(sstr));
  6569. loc = strstr(str, "startTime");
  6570. if(loc == NULL)
  6571. {
  6572. startTimeIsNULL = TRUE;
  6573. }
  6574. else
  6575. {
  6576. while (loc[3+strlen("startTime")+c] != '\"')
  6577. {
  6578. sstr[c] = loc[3+strlen("startTime")+c];
  6579. c++;
  6580. }
  6581. sstr[c] = '\0';
  6582. strcpy(startTimestr,sstr);
  6583. }
  6584. //****************stopTime*******************/
  6585. c = 0;
  6586. memset(sstr ,0, ARRAY_SIZE(sstr));
  6587. loc = strstr(str, "stopTime");
  6588. if(loc == NULL)
  6589. {
  6590. stopTimeIsNULL = TRUE;
  6591. }
  6592. else
  6593. {
  6594. while (loc[3+strlen("stopTime")+c] != '\"')
  6595. {
  6596. sstr[c] = loc[3+strlen("stopTime")+c];
  6597. c++;
  6598. }
  6599. sstr[c] = '\0';
  6600. strcpy(stopTimestr,sstr);
  6601. }
  6602. memset(protocol, 0, ARRAY_SIZE(protocol));
  6603. memset(user, 0, ARRAY_SIZE(user) );
  6604. memset(password, 0, ARRAY_SIZE(password));
  6605. memset(host, 0, ARRAY_SIZE(host));
  6606. memset(path, 0, ARRAY_SIZE(path));
  6607. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6608. memset(host1, 0, ARRAY_SIZE(host1));
  6609. memset(path1, 0, ARRAY_SIZE(path1));
  6610. /*location: ftp://user:password@host:port/path*/
  6611. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6612. if((access(fnamePlusPath,F_OK))!=-1)
  6613. {
  6614. DEBUG_INFO("fnamePlusPath exist.\n");
  6615. }
  6616. else
  6617. {
  6618. DEBUG_INFO("fnamePlusPath not exist!\n");
  6619. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6620. goto end;
  6621. }
  6622. pch=strchr(locationstr,'@');
  6623. if(pch==NULL)
  6624. {
  6625. sscanf(locationstr,
  6626. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6627. protocol, host, &port, path);
  6628. strcpy(user,"anonymous");
  6629. strcpy(password,"");
  6630. }
  6631. else
  6632. {
  6633. //DEBUG_INFO("pch=%s\n", pch);
  6634. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6635. protocol, user, password, host, &port, path);
  6636. }
  6637. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6638. {
  6639. DEBUG_INFO("protocol is not ftp/http ! \n");
  6640. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6641. goto end;
  6642. }
  6643. if(strncmp(locationstr,"http", 4) == 0)
  6644. {
  6645. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6646. sprintf(ftppath,"/%s", path);
  6647. do{
  6648. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6649. sleep(retryIntervalInt);
  6650. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6651. if(!isSuccess)
  6652. {
  6653. DEBUG_INFO("Diagnostics fail.\n");
  6654. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6655. }
  6656. else
  6657. {
  6658. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6659. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6660. }
  6661. }
  6662. else
  6663. {
  6664. sscanf(host,"%[^/]%s",host1, path1);
  6665. sprintf(ftppath,"%s", path1);
  6666. int ftppathlen=strlen(ftppath);
  6667. int i=1;
  6668. char filenametemp[50];
  6669. while(i < ftppathlen)
  6670. {
  6671. int len=ftppathlen-i;
  6672. if(ftppath[len]== 47) // '/' ascll code: 47
  6673. {
  6674. DEBUG_INFO("find '/' all right\n");
  6675. break;
  6676. }
  6677. i=i+1;
  6678. }
  6679. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6680. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6681. filenametemp[i+1] = 0;
  6682. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6683. if(port == 0)
  6684. port = 21;
  6685. do{
  6686. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6687. sleep(retryIntervalInt);
  6688. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6689. if(!isSuccess)
  6690. {
  6691. DEBUG_INFO("Diagnostics fail.\n");
  6692. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6693. }
  6694. else
  6695. {
  6696. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6697. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6698. }
  6699. }
  6700. end:
  6701. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6702. pthread_exit(NULL);
  6703. }
  6704. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6705. {
  6706. mtrace();
  6707. int result = FAIL;
  6708. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6709. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6710. {
  6711. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6712. localversion = -1;
  6713. }
  6714. else
  6715. {
  6716. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6717. OCPP_getListVerion();
  6718. }
  6719. //from db.OCPP_getListVerion
  6720. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6721. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6722. sendGetLocalListVersionConfirmation(uuid,"");
  6723. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6724. return result;
  6725. }
  6726. int handleRemoteStartRequest(char *uuid, char *payload)
  6727. {
  6728. mtrace();
  6729. int result = FAIL;
  6730. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6731. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6732. int tempIndex = 0;
  6733. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6734. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6735. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6736. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6737. int chargingSchedulePeriodCount = 0;
  6738. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6739. int c = 0;
  6740. char *loc;
  6741. char comfirmstr[20]={0};
  6742. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6743. if(server_pending == TRUE)
  6744. {
  6745. return 0;
  6746. }
  6747. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6748. strcpy(sstrtemp, stringtrimspace(payload));
  6749. //**********connectorId****************/
  6750. c = 0;
  6751. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6752. loc = strstr(sstrtemp, "connectorId");
  6753. if(loc == NULL)
  6754. {
  6755. connectorIdIsNULL = TRUE;
  6756. }
  6757. else
  6758. {
  6759. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6760. {
  6761. sstr[c] = loc[strlen("connectorId")+2+c];
  6762. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6763. c++;
  6764. }
  6765. sstr[c] = '\0';
  6766. connectorIdInt = atoi(sstr);
  6767. }
  6768. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6769. {
  6770. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6771. goto end;
  6772. }
  6773. //****************idTag*******************/
  6774. c = 0;
  6775. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6776. loc = strstr(sstrtemp, "idTag");
  6777. while (loc[3+strlen("idTag")+c] != '\"')
  6778. {
  6779. sstr[c] = loc[3+strlen("idTag")+c];
  6780. c++;
  6781. }
  6782. sstr[c] = '\0';
  6783. strcpy(idTagstr,sstr);
  6784. //****************chargingProfile*******************/
  6785. c = 0;
  6786. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6787. loc = strstr(sstrtemp, "chargingProfile");
  6788. if(loc == NULL)
  6789. {
  6790. chargingProfileIsNULL = TRUE;
  6791. }
  6792. else
  6793. {
  6794. //****************chargingProfileId*******************/
  6795. c=0;
  6796. loc = strstr(sstrtemp, "chargingProfileId");
  6797. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6798. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6799. {
  6800. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6801. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6802. c++;
  6803. }
  6804. sstr[c] = '\0';
  6805. chargingProfileIdInt = atoi(sstr);
  6806. //****************transactionId*******************/
  6807. loc = strstr(sstrtemp, "transactionId");
  6808. if(loc == NULL)
  6809. {
  6810. transactionIdIsNULL = TRUE;
  6811. }
  6812. else
  6813. {
  6814. c=0;
  6815. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6816. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6817. {
  6818. sstr[c] = loc[strlen("transactionId")+2+c];
  6819. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6820. c++;
  6821. }
  6822. sstr[c] = '\0';
  6823. transactionIdInt = atoi(sstr);
  6824. }
  6825. //****************stackLevel*******************/
  6826. c=0;
  6827. loc = strstr(sstrtemp, "stackLevel");
  6828. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6829. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6830. {
  6831. sstr[c] = loc[strlen("stackLevel")+2+c];
  6832. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6833. c++;
  6834. }
  6835. sstr[c] = '\0';
  6836. stackLevelInt = atoi(sstr);
  6837. //****************chargingProfilePurpose*******************/
  6838. c = 0;
  6839. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6840. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6841. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6842. {
  6843. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6844. c++;
  6845. }
  6846. sstr[c] = '\0';
  6847. strcpy(chargingProfilePurposestr,sstr);
  6848. //****************chargingProfileKind*******************/
  6849. c = 0;
  6850. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6851. loc = strstr(sstrtemp, "chargingProfileKind");
  6852. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6853. {
  6854. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6855. c++;
  6856. }
  6857. sstr[c] = '\0';
  6858. strcpy(chargingProfileKindstr,sstr);
  6859. //****************recurrencyKind*******************/
  6860. loc = strstr(sstrtemp, "recurrencyKind");
  6861. if(loc == NULL)
  6862. {
  6863. recurrencyKindIsNULL = TRUE;
  6864. }
  6865. else
  6866. {
  6867. c = 0;
  6868. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6869. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6870. {
  6871. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6872. c++;
  6873. }
  6874. sstr[c] = '\0';
  6875. strcpy(recurrencyKindstr,sstr);
  6876. }
  6877. //****************validFrom*******************/
  6878. loc = strstr(sstrtemp, "validFrom");
  6879. if(loc == NULL)
  6880. {
  6881. validFromIsNULL = TRUE;
  6882. }
  6883. else
  6884. {
  6885. c = 0;
  6886. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6887. while (loc[3+strlen("validFrom")+c] != '\"')
  6888. {
  6889. sstr[c] = loc[3+strlen("validFrom")+c];
  6890. c++;
  6891. }
  6892. sstr[c] = '\0';
  6893. strcpy(validFromstr,sstr);
  6894. }
  6895. //****************validTo*******************/
  6896. loc = strstr(sstrtemp, "validTo");
  6897. if(loc == NULL)
  6898. {
  6899. validToIsNULL = TRUE;
  6900. }
  6901. else
  6902. {
  6903. c = 0;
  6904. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6905. while (loc[3+strlen("validTo")+c] != '\"')
  6906. {
  6907. sstr[c] = loc[3+strlen("validTo")+c];
  6908. c++;
  6909. }
  6910. sstr[c] = '\0';
  6911. strcpy(validTostr,sstr);
  6912. }
  6913. //****************chargingSchedule*******************/
  6914. loc = strstr(sstrtemp, "chargingSchedule");
  6915. if(loc != NULL)
  6916. {
  6917. //****************duration*******************/
  6918. loc = strstr(sstrtemp, "duration");
  6919. if(loc == NULL)
  6920. {
  6921. durationIsNULL = TRUE;
  6922. }
  6923. else
  6924. {
  6925. c=0;
  6926. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6927. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6928. {
  6929. sstr[c] = loc[strlen("duration")+2+c];
  6930. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6931. c++;
  6932. }
  6933. sstr[c] = '\0';
  6934. durationInt = atoi(sstr);
  6935. }
  6936. //****************startSchedule******************/
  6937. loc = strstr(sstrtemp, "startSchedule");
  6938. if(loc == NULL)
  6939. {
  6940. startScheduleIsNULL = TRUE;
  6941. }
  6942. else
  6943. {
  6944. c = 0;
  6945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6946. while (loc[3+strlen("startSchedule")+c] != '\"')
  6947. {
  6948. sstr[c] = loc[3+strlen("startSchedule")+c];
  6949. c++;
  6950. }
  6951. sstr[c] = '\0';
  6952. strcpy(startSchedulestr,sstr);
  6953. }
  6954. //****************chargingRateUnit*******************/
  6955. c = 0;
  6956. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6957. loc = strstr(sstrtemp, "chargingRateUnit");
  6958. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6959. {
  6960. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6961. c++;
  6962. }
  6963. sstr[c] = '\0';
  6964. strcpy(chargingRateUnitstr,sstr);
  6965. //****************minChargingRate*******************/
  6966. loc = strstr(sstrtemp, "minChargingRate");
  6967. if(loc == NULL)
  6968. {
  6969. minChargingRateIsNULL = TRUE;
  6970. }
  6971. else
  6972. {
  6973. c=0;
  6974. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6975. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6976. {
  6977. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6979. c++;
  6980. }
  6981. sstr[c] = '\0';
  6982. minChargingRateflaot = atof(sstr);
  6983. }
  6984. //****************chargingSchedulePeriod count*******************/
  6985. int what_len = strlen("startPeriod");
  6986. char *where = sstrtemp;
  6987. while ((where = strstr(where, "startPeriod"))) {
  6988. where += what_len;
  6989. chargingSchedulePeriodCount++;
  6990. }
  6991. where = sstrtemp;
  6992. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6993. {
  6994. //****************startPeriod*******************/
  6995. c=0;
  6996. loc = strstr(where, "startPeriod");
  6997. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6998. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6999. {
  7000. sstr[c] = loc[strlen("startPeriod")+2+c];
  7001. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7002. c++;
  7003. }
  7004. sstr[c] = '\0';
  7005. startPeriodInt[periodNums] = atoi(sstr);
  7006. //****************limit*******************/
  7007. c=0;
  7008. loc = strstr(where, "limit");
  7009. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7010. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7011. {
  7012. sstr[c] = loc[strlen("limit")+2+c];
  7013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7014. c++;
  7015. }
  7016. sstr[c] = '\0';
  7017. limitflaot[periodNums] = atof(sstr);
  7018. //****************numberPhases*******************/
  7019. loc = strstr(where, "numberPhases");
  7020. if(loc == NULL)
  7021. {
  7022. numberPhasesIsNULL = TRUE;
  7023. }
  7024. else
  7025. {
  7026. c=0;
  7027. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7028. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7029. {
  7030. sstr[c] = loc[strlen("numberPhases")+2+c];
  7031. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7032. c++;
  7033. }
  7034. sstr[c] = '\0';
  7035. numberPhasesInt[periodNums] = atoi(sstr);
  7036. }
  7037. where = loc;
  7038. } // END FOR chargingSchedulePeriodCount
  7039. }// END IF chargingSchedule
  7040. } // END chargingProfile
  7041. /*
  7042. enum _SYSTEM_STATUS
  7043. {
  7044. S_BOOTING = 0,
  7045. S_IDLE, = 1
  7046. S_AUTHORIZING, =2
  7047. S_REASSIGN_CHECK, =3
  7048. S_REASSIGN, =4
  7049. S_PRECHARGE, =5
  7050. S_PREPARING_FOR_EV, =6
  7051. S_PREPARING_FOR_EVSE, =7
  7052. S_CHARGING, =8
  7053. S_TERMINATING, =9
  7054. S_COMPLETE, =10
  7055. S_ALARM, =11
  7056. S_FAULT =12
  7057. }
  7058. */
  7059. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7060. {
  7061. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7062. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7063. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7064. //check Transaction active
  7065. if(gunType[connectorIdInt -1] == 'J')
  7066. {
  7067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7068. {
  7069. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7070. }
  7071. else
  7072. {
  7073. tempIndex = connectorIdInt -1;
  7074. }
  7075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7078. {
  7079. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7080. {
  7081. //Reserved
  7082. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7083. }
  7084. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7085. {
  7086. //Reserved
  7087. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7089. goto end;
  7090. }
  7091. else
  7092. {
  7093. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7094. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7096. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7097. {
  7098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7099. goto end;
  7100. }
  7101. }//END FOR ELSE
  7102. }
  7103. }// END FOR CHAdeMO_QUANTITY
  7104. }
  7105. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7106. {
  7107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7108. {
  7109. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7110. }
  7111. else
  7112. {
  7113. tempIndex = connectorIdInt -1;
  7114. }
  7115. for (int index = 0; index < CCS_QUANTITY; index++)
  7116. {
  7117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7118. {
  7119. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7120. {
  7121. //Reserved
  7122. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7123. }
  7124. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7125. {
  7126. //Reserved
  7127. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7128. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7129. goto end;
  7130. }
  7131. else
  7132. {
  7133. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7134. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7135. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7136. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7137. {
  7138. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7139. goto end;
  7140. }
  7141. }// END FOR ELSE
  7142. }
  7143. }// END FOR CCS_QUANTITY
  7144. }
  7145. else if(gunType[connectorIdInt -1] == 'G')
  7146. {
  7147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7148. {
  7149. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7150. }
  7151. else
  7152. {
  7153. tempIndex = connectorIdInt -1;
  7154. }
  7155. for (int index = 0; index < GB_QUANTITY; index++)
  7156. {
  7157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7158. {
  7159. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7160. {
  7161. //Reserved
  7162. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7163. }
  7164. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7165. {
  7166. //Reserved
  7167. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7168. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7169. goto end;
  7170. }
  7171. else
  7172. {
  7173. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7174. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7175. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7176. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7177. {
  7178. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7179. goto end;
  7180. }
  7181. }// END FOR ELSE
  7182. }
  7183. } // END FOR GB_QUANTITY
  7184. }
  7185. else
  7186. {
  7187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7188. {
  7189. tempIndex = 2;
  7190. }
  7191. else
  7192. {
  7193. tempIndex = connectorIdInt -1;
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7198. {
  7199. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7200. {
  7201. //Reserved
  7202. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7203. }
  7204. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7205. {
  7206. //Reserved
  7207. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7209. goto end;
  7210. }
  7211. else
  7212. {
  7213. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7214. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7215. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7216. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7217. {
  7218. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7219. goto end;
  7220. }
  7221. }//END FOR ELSE
  7222. }
  7223. }// END FOR AC_QUANTITY
  7224. }
  7225. if(chargingProfileIsNULL == FALSE)
  7226. {
  7227. //ChargingProfile
  7228. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7229. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7230. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7231. if(recurrencyKindIsNULL == FALSE) //OPTION
  7232. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7233. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7234. if(transactionIdIsNULL == FALSE) // OPTION
  7235. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7236. if(validFromIsNULL == FALSE) // OPTION
  7237. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7238. if(validToIsNULL == FALSE) //OPTION
  7239. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7240. //ChargingSchedule
  7241. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7242. if(durationIsNULL == FALSE) //OPTION
  7243. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7244. if(minChargingRateIsNULL == FALSE) //OPTION
  7245. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7246. if(startScheduleIsNULL == FALSE) //OPTION
  7247. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7248. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7249. {
  7250. //ChargingSchedulePeriod
  7251. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7252. if(numberPhasesIsNULL == FALSE)
  7253. {
  7254. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7255. }
  7256. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7257. }
  7258. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7259. {
  7260. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7261. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7262. //memset idTag
  7263. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7264. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7265. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7266. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7267. }
  7268. else
  7269. {
  7270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7271. }
  7272. }
  7273. else
  7274. {
  7275. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7277. //memset idTag
  7278. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7279. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7280. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7281. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7282. }
  7283. }
  7284. else
  7285. {
  7286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7287. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7288. }
  7289. end:
  7290. if(connectorIdIsNULL == FALSE)
  7291. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7292. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7293. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7294. //OCPP send RemoteStartConfirmation by first.
  7295. sendRemoteStartConfirmation(uuid, comfirmstr);
  7296. return result;
  7297. }
  7298. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7299. {
  7300. mtrace();
  7301. int result = FAIL;
  7302. int match = FALSE;
  7303. int GunNO = 0;
  7304. int tempIndex = 0;
  7305. int transactionIdInt=0;
  7306. int transactionIdIsNULL= FALSE;
  7307. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7308. int c = 0;
  7309. char *loc;
  7310. char comfirmstr[20];
  7311. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7312. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7313. if(server_pending == TRUE)
  7314. {
  7315. return 0;
  7316. }
  7317. strcpy(sstrtemp, stringtrimspace(payload));
  7318. c=0;
  7319. loc = strstr(sstrtemp, "transactionId");
  7320. if(loc == NULL)
  7321. {
  7322. transactionIdIsNULL= TRUE;
  7323. }
  7324. else
  7325. {
  7326. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7327. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7328. {
  7329. sstr[c] = loc[strlen("transactionId")+2+c];
  7330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7331. c++;
  7332. }
  7333. sstr[c] = '\0';
  7334. transactionIdInt = atoi(sstr);
  7335. }
  7336. if(transactionIdIsNULL == FALSE)
  7337. {
  7338. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7339. {
  7340. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7341. {
  7342. //check Transaction active
  7343. if(gunType[gun_index] == 'J')
  7344. {
  7345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7346. {
  7347. tempIndex = ((gun_index==2) ? 1: 0);
  7348. }
  7349. else
  7350. {
  7351. tempIndex = gun_index;
  7352. }
  7353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7354. {
  7355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7356. {
  7357. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7358. {
  7359. match = TRUE;
  7360. GunNO = gun_index;
  7361. }
  7362. }
  7363. }// END FOR CHAdeMO_QUANTITY
  7364. }
  7365. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7366. {
  7367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7368. {
  7369. tempIndex = ((gun_index==2) ? 1: 0);
  7370. }
  7371. else
  7372. {
  7373. tempIndex = gun_index;
  7374. }
  7375. for (int index = 0; index < CCS_QUANTITY; index++)
  7376. {
  7377. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7378. {
  7379. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7380. {
  7381. match = TRUE;
  7382. GunNO = gun_index;
  7383. }
  7384. }
  7385. }// END FOR CCS_QUANTITY
  7386. }
  7387. else if(gunType[gun_index] == 'G')
  7388. {
  7389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7390. {
  7391. tempIndex = ((gun_index==2) ? 1: 0);
  7392. }
  7393. else
  7394. {
  7395. tempIndex = gun_index;
  7396. }
  7397. for (int index = 0; index < GB_QUANTITY; index++)
  7398. {
  7399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7400. {
  7401. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7402. {
  7403. match = TRUE;
  7404. GunNO = gun_index;
  7405. }
  7406. }
  7407. }// END FOR GB_QUANTITY
  7408. }
  7409. else
  7410. {
  7411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7412. {
  7413. tempIndex = 2;
  7414. }
  7415. else
  7416. {
  7417. tempIndex = gun_index;
  7418. }
  7419. for (int index = 0; index < AC_QUANTITY; index++)
  7420. {
  7421. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7422. {
  7423. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7424. {
  7425. match = TRUE;
  7426. GunNO = gun_index;
  7427. }
  7428. }
  7429. }// END FOR CHAdeMO_QUANTITY
  7430. } // END FOR AC ELSE
  7431. }// CHECK IF ResponseTransactionId == transactionIdInt
  7432. }//END FOR
  7433. if( match == TRUE)
  7434. {
  7435. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7436. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7437. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7438. }
  7439. else
  7440. {
  7441. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7442. }
  7443. }
  7444. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7445. return result;
  7446. }
  7447. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7448. {
  7449. mtrace();
  7450. int result = FAIL;
  7451. int connectorIdInt=0, reservationIdInt=0;
  7452. int tempIndex = 0;
  7453. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7454. char comfirmstr[20]={0};
  7455. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7456. int c = 0;
  7457. char *loc;
  7458. //char *ptr;
  7459. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7460. strcpy(sstrtemp, stringtrimspace(payload));
  7461. //***(1)connectorId ****/
  7462. c=0;
  7463. loc = strstr(sstrtemp, "connectorId");
  7464. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7465. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7466. {
  7467. sstr[c] = loc[strlen("connectorId")+2+c];
  7468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7469. c++;
  7470. }
  7471. sstr[c] = '\0';
  7472. connectorIdInt = atoi(sstr);
  7473. //***(2)expiryDate ****/
  7474. loc = strstr(sstrtemp, "expiryDate");
  7475. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7476. c = 0;
  7477. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7478. {
  7479. sstr[c] = loc[3+strlen("expiryDate")+c];
  7480. c++;
  7481. }
  7482. sstr[c] = '\0';
  7483. strcpy(expiryDatestr, sstr);
  7484. //***(3)idTag ****/
  7485. loc = strstr(sstrtemp, "idTag");
  7486. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7487. c = 0;
  7488. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7489. {
  7490. sstr[c] = loc[3+strlen("idTag")+c];
  7491. c++;
  7492. }
  7493. sstr[c] = '\0';
  7494. strcpy(idTagstr, sstr);
  7495. //***(4)parentIdTag ****/
  7496. loc = strstr(sstrtemp, "parentIdTag");
  7497. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7498. c = 0;
  7499. if(loc == NULL)
  7500. {
  7501. strcpy(parentIdTagstr, "");
  7502. }
  7503. else
  7504. {
  7505. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7506. {
  7507. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7508. c++;
  7509. }
  7510. sstr[c] = '\0';
  7511. strcpy(parentIdTagstr, sstr);
  7512. }
  7513. //***(5)reservationId ****/
  7514. c=0;
  7515. loc = strstr(sstrtemp, "reservationId");
  7516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7517. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7518. {
  7519. sstr[c] = loc[strlen("reservationId")+2+c];
  7520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7521. c++;
  7522. }
  7523. sstr[c] = '\0';
  7524. reservationIdInt = atoi(sstr);
  7525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7526. /*
  7527. enum SYSTEM_STATUS
  7528. {
  7529. SYS_MODE_BOOTING = 0,
  7530. SYS_MODE_IDLE = 1,
  7531. SYS_MODE_AUTHORIZING = 2,
  7532. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7533. SYS_MODE_REASSIGN = 4,
  7534. SYS_MODE_PREPARING = 5,
  7535. SYS_MODE_PREPARE_FOR_EV = 6,
  7536. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7537. SYS_MODE_CHARGING = 8,
  7538. SYS_MODE_TERMINATING = 9,
  7539. SYS_MODE_COMPLETE = 10,
  7540. SYS_MODE_ALARM = 11,
  7541. SYS_MODE_FAULT = 12,
  7542. SYS_MODE_RESERVATION = 13,
  7543. SYS_MODE_BOOKING = 14,
  7544. SYS_MODE_MAINTAIN = 15,
  7545. SYS_MODE_DEBUG = 16,
  7546. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7547. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7548. SYS_MODE_UPDATE = 19
  7549. };
  7550. */
  7551. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7552. {
  7553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7554. goto end;
  7555. }
  7556. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7557. {
  7558. //check Transaction active
  7559. if(gunType[connectorIdInt -1] == 'J')
  7560. {
  7561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7562. {
  7563. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7564. }
  7565. else
  7566. {
  7567. tempIndex = connectorIdInt -1;
  7568. }
  7569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7570. {
  7571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7572. {
  7573. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7574. {
  7575. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7576. {
  7577. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7578. {
  7579. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7581. }
  7582. 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'))
  7583. {
  7584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7585. }
  7586. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7587. {
  7588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7589. }
  7590. else
  7591. {
  7592. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7593. }
  7594. }
  7595. 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
  7596. {
  7597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7598. }
  7599. }
  7600. else
  7601. {
  7602. //replace reservation
  7603. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7605. }
  7606. }
  7607. } // END FOR CHAdeMO_QUANTITY
  7608. }
  7609. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7610. {
  7611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7612. {
  7613. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7614. }
  7615. else
  7616. {
  7617. tempIndex = connectorIdInt -1;
  7618. }
  7619. for (int index = 0; index < CCS_QUANTITY; index++)
  7620. {
  7621. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7622. {
  7623. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7624. {
  7625. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7626. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7627. {
  7628. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7629. {
  7630. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7632. }
  7633. 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'))
  7634. {
  7635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7636. }
  7637. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7638. {
  7639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7640. }
  7641. else
  7642. {
  7643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7644. }
  7645. }
  7646. 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
  7647. {
  7648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7649. }
  7650. }
  7651. else
  7652. {
  7653. //replace reservation
  7654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7656. }
  7657. }
  7658. } // END FOR CCS_QUANTITY
  7659. }
  7660. else if(gunType[connectorIdInt -1] == 'G')
  7661. {
  7662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7663. {
  7664. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7665. }
  7666. else
  7667. {
  7668. tempIndex = connectorIdInt -1;
  7669. }
  7670. for (int index = 0; index < GB_QUANTITY; index++)
  7671. {
  7672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7673. {
  7674. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7675. {
  7676. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7677. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7678. {
  7679. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7680. {
  7681. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7683. }
  7684. 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'))
  7685. {
  7686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7687. }
  7688. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7689. {
  7690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7691. }
  7692. else
  7693. {
  7694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7695. }
  7696. }
  7697. 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
  7698. {
  7699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7700. }
  7701. }
  7702. else
  7703. {
  7704. //replace reservation
  7705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7707. }
  7708. }
  7709. }// END FOR GB_QUANTITY
  7710. }
  7711. else
  7712. {
  7713. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7714. {
  7715. tempIndex = 2;
  7716. }
  7717. else
  7718. {
  7719. tempIndex = (connectorIdInt -1);
  7720. }
  7721. for (int index = 0; index < AC_QUANTITY; index++)
  7722. {
  7723. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7724. {
  7725. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7726. {
  7727. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7728. {
  7729. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7730. {
  7731. 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))
  7732. {
  7733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7734. }
  7735. else
  7736. {
  7737. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7739. }
  7740. }
  7741. 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'))
  7742. {
  7743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7744. }
  7745. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7746. {
  7747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7748. }
  7749. else
  7750. {
  7751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7752. }
  7753. }
  7754. 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
  7755. {
  7756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7757. }
  7758. }
  7759. else
  7760. {
  7761. //replace reservation
  7762. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7764. }
  7765. }
  7766. } // END FOR AC_QUANTITY
  7767. }
  7768. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7769. }
  7770. else if(connectorIdInt == 0)
  7771. {
  7772. //check Transaction active
  7773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7774. {
  7775. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7776. {
  7777. 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'))
  7778. {
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7780. goto end;
  7781. }
  7782. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7783. {
  7784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7785. goto end;
  7786. }
  7787. 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
  7788. {
  7789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7790. goto end;
  7791. }
  7792. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7793. {
  7794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7795. goto end;
  7796. }
  7797. }
  7798. }// END FOR CHAdeMO_QUANTITY
  7799. for (int index = 0; index < CCS_QUANTITY; index++)
  7800. {
  7801. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7802. {
  7803. 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'))
  7804. {
  7805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7806. goto end;
  7807. }
  7808. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7809. {
  7810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7811. goto end;
  7812. }
  7813. 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
  7814. {
  7815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7816. goto end;
  7817. }
  7818. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7819. {
  7820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7821. goto end;
  7822. }
  7823. }
  7824. } // END FOR CCS_QUANTITY
  7825. for (int index = 0; index < GB_QUANTITY; index++)
  7826. {
  7827. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7828. {
  7829. 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'))
  7830. {
  7831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7832. goto end;
  7833. }
  7834. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7835. {
  7836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7837. goto end;
  7838. }
  7839. 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
  7840. {
  7841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7842. goto end;
  7843. }
  7844. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7845. {
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7847. goto end;
  7848. }
  7849. }
  7850. } // END FOR GB_QUANTITY
  7851. for (int index = 0; index < AC_QUANTITY; index++)
  7852. {
  7853. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7854. {
  7855. 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'))
  7856. {
  7857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7858. goto end;
  7859. }
  7860. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7861. {
  7862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7863. goto end;
  7864. }
  7865. 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
  7866. {
  7867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7868. goto end;
  7869. }
  7870. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7871. {
  7872. 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))
  7873. {
  7874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7875. goto end;
  7876. }
  7877. }
  7878. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7879. {
  7880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7881. goto end;
  7882. }
  7883. }
  7884. }// END FOR AC_QUANTITY
  7885. //The connectorId is 0
  7886. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7888. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7889. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7890. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7891. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7892. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7893. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7894. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7895. result = TRUE;
  7896. return result;
  7897. }
  7898. else
  7899. {
  7900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7901. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7902. }
  7903. if(strcmp(comfirmstr,"Accepted") == 0)
  7904. {
  7905. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7906. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7907. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7908. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7909. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7910. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7911. result = TRUE;
  7912. return result;
  7913. }
  7914. end:
  7915. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7916. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7917. return result;
  7918. }
  7919. int handleResetRequest(char *uuid, char *payload)
  7920. {
  7921. mtrace();
  7922. int result = FAIL;
  7923. char sstr[10]={0},sstrtemp[30]={ 0 };
  7924. char typestr[10]={0};
  7925. char comfirmstr[20]={0};
  7926. int c = 0;
  7927. char *loc;
  7928. DEBUG_INFO("handleResetRequest...\n");
  7929. strcpy(sstrtemp, stringtrimspace(payload));
  7930. loc = strstr(sstrtemp, "type");
  7931. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7932. c = 0;
  7933. while (loc[3+strlen("type")+c] != '\"')
  7934. {
  7935. sstr[c] = loc[3+strlen("type")+c];
  7936. c++;
  7937. }
  7938. sstr[c] = '\0';
  7939. strcpy(typestr,sstr);
  7940. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7941. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7942. {
  7943. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7944. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7945. result = TRUE;
  7946. return result;
  7947. }
  7948. else
  7949. {
  7950. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7951. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7952. goto errorend;
  7953. }
  7954. errorend:
  7955. sendResetConfirmation(uuid, comfirmstr);
  7956. return result;
  7957. }
  7958. int handleSendLocalListRequest(char *uuid, char *payload)
  7959. {
  7960. mtrace();
  7961. int result = FAIL;
  7962. int listVersionInt;
  7963. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7964. char listsearch[]="listVersion";
  7965. char updateTypesearch[]="updateType";
  7966. char localAuthorizationListsearch[]="localAuthorizationList";
  7967. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7968. char CardList[500][160]={0};
  7969. char updateTypestr[15]={0};
  7970. char idTagstr[20]={0};
  7971. char parentIdTag[20]={0};
  7972. char expiryDate[30]={0};
  7973. char idTagstatus[16]={0};
  7974. int c = 0;
  7975. int i = 0;
  7976. char *delim1 = "}";
  7977. char * pch;
  7978. char *loc;
  7979. //char *ptr;
  7980. char comfirmstr[20];
  7981. //int n_localAuthorizations = 0;
  7982. int checkState_Faulted = FALSE;
  7983. DEBUG_INFO("handleSendLocalListRequest...\n");
  7984. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7985. {
  7986. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7987. goto end;
  7988. }
  7989. //check Charge Point state
  7990. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7991. {
  7992. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7993. {
  7994. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7995. }
  7996. }
  7997. for (int index = 0; index < CCS_QUANTITY; index++)
  7998. {
  7999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8000. {
  8001. checkState_Faulted = TRUE; //OCPP Status
  8002. }
  8003. }
  8004. for (int index = 0; index < GB_QUANTITY; index++)
  8005. {
  8006. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8007. {
  8008. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8009. }
  8010. }
  8011. //check Charge Point state
  8012. for (int index = 0; index < AC_QUANTITY; index++)
  8013. {
  8014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8015. {
  8016. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8017. }
  8018. }
  8019. if(checkState_Faulted == TRUE)
  8020. {
  8021. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8022. goto end;
  8023. }
  8024. //Filter payload space
  8025. strcpy(sstrtemp, stringtrimspace(payload));
  8026. //listVersion
  8027. c = 0;
  8028. loc = strstr(sstrtemp, listsearch);
  8029. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8030. {
  8031. sstr[c] = loc[strlen("listVersion")+2+c];
  8032. c++;
  8033. }
  8034. sstr[c] = '\0';
  8035. listVersionInt = atoi(sstr);
  8036. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8037. //updateType
  8038. loc = strstr(sstrtemp, updateTypesearch);
  8039. c = 0;
  8040. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8041. {
  8042. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8043. c++;
  8044. }
  8045. sstr[c] = '\0';
  8046. strcpy(updateTypestr, sstr);
  8047. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8048. //localAuthorizationList
  8049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8050. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8051. if(loc != NULL) // localAuthorizationList is not NULL
  8052. {
  8053. //Check UpdateType
  8054. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8055. {
  8056. //Local list full update
  8057. printf("Local list full update.\n");
  8058. OCPP_getListVerion();
  8059. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8060. {
  8061. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8062. goto end;
  8063. }
  8064. OCPP_cleanLocalList();
  8065. }
  8066. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8067. {
  8068. //Local list different update
  8069. printf("Local list different update.\n");
  8070. OCPP_getListVerion();
  8071. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8072. {
  8073. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8074. goto end;
  8075. }
  8076. }
  8077. else
  8078. {
  8079. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8080. goto end;
  8081. }
  8082. c = 0;
  8083. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8084. {
  8085. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8087. c++;
  8088. }
  8089. sstr[c] = '\0';
  8090. //DEBUG_INFO("sstr=%s\n", sstr);
  8091. //parsing strings to words
  8092. i = 0;
  8093. pch = strtok(sstr,delim1);
  8094. while (pch != NULL)
  8095. {
  8096. strcpy(CardList[i], pch);
  8097. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8098. pch = strtok (NULL, delim1);
  8099. i = i + 1;
  8100. }
  8101. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8102. //local Authorizations List Numbers
  8103. //n_localAuthorizations = i;
  8104. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8105. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8106. c= 0;
  8107. while(c < i) // i is CardList Number
  8108. {
  8109. //Search "IdToken"
  8110. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8111. loc = strstr(CardList[c], "idTag");
  8112. int j = 0;
  8113. while (loc[3+strlen("idTag")+j] != '\"')
  8114. {
  8115. sstr[j] = loc[3+strlen("idTag")+j];
  8116. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8117. j++;
  8118. }
  8119. sstr[j] = '\0';
  8120. strcpy(idTagstr, sstr);
  8121. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8122. //Search "expiryDate"
  8123. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8124. loc = strstr(CardList[c], "expiryDate");
  8125. j = 0;
  8126. if(loc != NULL)
  8127. {
  8128. while (loc[3+strlen("expiryDate")+j] != '\"')
  8129. {
  8130. sstr[j] = loc[3+strlen("expiryDate")+j];
  8131. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8132. j++;
  8133. }
  8134. sstr[j] = '\0';
  8135. strcpy(expiryDate, sstr);
  8136. }
  8137. else
  8138. {
  8139. strcpy(expiryDate, "");
  8140. }
  8141. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8142. //Search "parentIdTag"
  8143. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8144. loc = strstr(CardList[c], "parentIdTag");
  8145. j = 0;
  8146. if(loc != NULL)
  8147. {
  8148. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8149. {
  8150. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8151. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8152. j++;
  8153. }
  8154. sstr[j] = '\0';
  8155. strcpy(parentIdTag, sstr);
  8156. }
  8157. else
  8158. {
  8159. strcpy(parentIdTag, "");
  8160. }
  8161. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8162. //Search "status"
  8163. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8164. loc = strstr(CardList[c], "status");
  8165. j = 0;
  8166. while (loc[3+strlen("status")+j] != '\"')
  8167. {
  8168. sstr[j] = loc[3+strlen("status")+j];
  8169. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8170. j++;
  8171. }
  8172. sstr[j] = '\0';
  8173. strcpy(idTagstatus, sstr);
  8174. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8175. OCPP_getIdTag(idTagstr);
  8176. //OCPP_getIdTag("test"); For Test
  8177. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8178. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8179. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8180. {
  8181. //Local list full update
  8182. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8183. // update list
  8184. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8185. //DEBUG_INFO("Local list full update. 1\n");
  8186. //OCPP_get_TableAuthlocalAllData();
  8187. //DEBUG_INFO("Local list full update. 2\n");
  8188. }
  8189. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8190. {
  8191. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8192. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8193. }
  8194. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8195. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8196. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8197. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8198. c++;
  8199. }
  8200. }
  8201. else
  8202. {
  8203. //Check UpdateType
  8204. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8205. {
  8206. //Local list full update
  8207. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8208. OCPP_cleanLocalList();
  8209. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8210. goto end;
  8211. }
  8212. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8213. {
  8214. //Local list different update
  8215. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8216. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8217. goto end;
  8218. }
  8219. }
  8220. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8221. end:
  8222. sendSendLocalListConfirmation(uuid, comfirmstr);
  8223. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8224. return result;
  8225. }
  8226. #define MAX 200
  8227. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8228. {
  8229. mtrace();
  8230. int result = FAIL;
  8231. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8232. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8233. char chargingProfilePurposeStr[30]={0};
  8234. char chargingProfileKindStr[16]={0};
  8235. char recurrencyKindStr[10]={0};
  8236. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8237. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8238. int chargingSchedulePeriodCount = 0;
  8239. //int updateflag = FALSE;
  8240. char comfirmstr[20]={0};
  8241. int meet= FALSE;
  8242. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8243. int c = 0;
  8244. char *loc;
  8245. FILE *fptr1;//, *fptr2;
  8246. //int lno=0;//, linectr = 0;
  8247. //int modifyflag = FALSE;
  8248. char filename[MAX]={0};
  8249. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8250. //int resultRename=0;
  8251. char rmFileCmd[50]={0};
  8252. char tempchargingProfilePurposeStr[30]={0};
  8253. char word[1600]={0};
  8254. int n_chargingProfile = 0;
  8255. //[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}}}]
  8256. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8257. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8258. //Filter string space
  8259. strcpy(sstrtemp, stringtrimspace(payload));
  8260. //*********************connectorId***************************/
  8261. loc = strstr(sstrtemp, "connectorId");
  8262. c = 0;
  8263. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8264. while (loc[strlen("connectorId")+2+c] != ',')
  8265. {
  8266. sstr[c] = loc[strlen("connectorId")+2+c];
  8267. c++;
  8268. }
  8269. sstr[c] = '\0';
  8270. connectorIdInt = atoi(sstr);
  8271. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8272. {
  8273. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8274. }
  8275. else
  8276. {
  8277. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8278. }
  8279. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8280. //*********************chargingProfileId***************************/
  8281. loc = strstr(sstrtemp, "chargingProfileId");
  8282. c = 0;
  8283. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8284. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8285. {
  8286. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8287. c++;
  8288. }
  8289. sstr[c] = '\0';
  8290. chargingProfileIdInt = atoi(sstr);
  8291. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8292. {
  8293. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8294. }
  8295. else
  8296. {
  8297. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8298. }
  8299. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8300. //*********************transactionId***************************/
  8301. loc = strstr(sstrtemp, "transactionId");
  8302. if(loc != NULL)
  8303. {
  8304. c = 0;
  8305. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8306. while (loc[strlen("transactionId")+2+c] != ',')
  8307. {
  8308. sstr[c] = loc[strlen("transactionId")+2+c];
  8309. c++;
  8310. }
  8311. sstr[c] = '\0';
  8312. transactionIdInt = atoi(sstr);
  8313. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8314. {
  8315. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8316. }
  8317. else
  8318. {
  8319. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8320. }
  8321. }
  8322. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8323. //*********************stackLevel***************************/
  8324. loc = strstr(sstrtemp, "stackLevel");
  8325. c = 0;
  8326. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8327. while (loc[strlen("stackLevel")+2+c] != ',')
  8328. {
  8329. sstr[c] = loc[strlen("stackLevel")+2+c];
  8330. c++;
  8331. }
  8332. sstr[c] = '\0';
  8333. stackLevelInt = atoi(sstr);
  8334. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8335. {
  8336. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8337. }
  8338. else
  8339. {
  8340. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8341. }
  8342. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8343. //*********************chargingProfilePurpose***************************/
  8344. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8345. c = 0;
  8346. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8347. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8348. {
  8349. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8350. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8351. c++;
  8352. }
  8353. sstr[c] = '\0';
  8354. strcpy(chargingProfilePurposeStr,sstr);
  8355. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8356. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8357. {
  8358. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8359. }
  8360. else
  8361. {
  8362. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8363. }
  8364. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8365. //*********************chargingProfileKind***************************/
  8366. loc = strstr(sstrtemp, "chargingProfileKind");
  8367. c = 0;
  8368. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8369. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8370. {
  8371. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8373. c++;
  8374. }
  8375. sstr[c] = '\0';
  8376. strcpy(chargingProfileKindStr,sstr);
  8377. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8378. {
  8379. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8380. }
  8381. else
  8382. {
  8383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8384. }
  8385. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8386. //*********************recurrencyKind***************************/
  8387. loc = strstr(sstrtemp, "recurrencyKind");
  8388. if(loc != NULL)
  8389. {
  8390. c = 0;
  8391. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8392. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8393. {
  8394. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8395. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8396. c++;
  8397. }
  8398. sstr[c] = '\0';
  8399. strcpy(recurrencyKindStr,sstr);
  8400. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8401. {
  8402. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8403. }
  8404. else
  8405. {
  8406. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8407. }
  8408. }
  8409. else
  8410. {
  8411. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8412. {
  8413. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8414. }
  8415. else
  8416. {
  8417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8418. }
  8419. }
  8420. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8421. //*********************validFrom***************************/
  8422. loc = strstr(sstrtemp, "validFrom");
  8423. if(loc != NULL)
  8424. {
  8425. c = 0;
  8426. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8427. while (loc[3+strlen("validFrom")+c] != '\"')
  8428. {
  8429. sstr[c] = loc[3+strlen("validFrom")+c];
  8430. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8431. c++;
  8432. }
  8433. sstr[c] = '\0';
  8434. strcpy(validFromStr,sstr);
  8435. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8436. {
  8437. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8438. }
  8439. else
  8440. {
  8441. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8442. }
  8443. }
  8444. else
  8445. {
  8446. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8447. {
  8448. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8449. }
  8450. else
  8451. {
  8452. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8453. }
  8454. }
  8455. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8456. //*********************validTo***************************/
  8457. loc = strstr(sstrtemp, "validTo");
  8458. if(loc != NULL)
  8459. {
  8460. c = 0;
  8461. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8462. while (loc[3+strlen("validTo")+c] != '\"')
  8463. {
  8464. sstr[c] = loc[3+strlen("validTo")+c];
  8465. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8466. c++;
  8467. }
  8468. sstr[c] = '\0';
  8469. strcpy(validToStr,sstr);
  8470. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8471. {
  8472. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8473. }
  8474. else
  8475. {
  8476. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8477. }
  8478. }
  8479. else
  8480. {
  8481. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8482. {
  8483. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8484. }
  8485. else
  8486. {
  8487. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8488. }
  8489. }
  8490. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8491. //*********************duration***************************/
  8492. loc = strstr(sstrtemp, "duration");
  8493. if(loc != NULL)
  8494. {
  8495. c = 0;
  8496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8497. while (loc[strlen("duration")+2+c] != ',')
  8498. {
  8499. sstr[c] = loc[strlen("duration")+2+c];
  8500. c++;
  8501. }
  8502. sstr[c] = '\0';
  8503. durationInt = atoi(sstr);
  8504. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8505. {
  8506. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8507. }
  8508. else
  8509. {
  8510. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8511. }
  8512. }
  8513. else
  8514. {
  8515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8516. {
  8517. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8518. }
  8519. else
  8520. {
  8521. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8522. }
  8523. }
  8524. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8525. //*********************startSchedule***************************/
  8526. loc = strstr(sstrtemp, "startSchedule");
  8527. if(loc != NULL)
  8528. {
  8529. c = 0;
  8530. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8531. while (loc[3+strlen("startSchedule")+c] != '\"')
  8532. {
  8533. sstr[c] = loc[3+strlen("startSchedule")+c];
  8534. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8535. c++;
  8536. }
  8537. sstr[c] = '\0';
  8538. strcpy(startScheduleStr,sstr);
  8539. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8540. {
  8541. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8542. }
  8543. else
  8544. {
  8545. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8546. }
  8547. }
  8548. else
  8549. {
  8550. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8551. {
  8552. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8553. }
  8554. else
  8555. {
  8556. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8557. }
  8558. }
  8559. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8560. //*********************chargingRateUnit***************************/
  8561. loc = strstr(sstrtemp, "chargingRateUnit");
  8562. if(loc != NULL)
  8563. {
  8564. c = 0;
  8565. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8566. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8567. {
  8568. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8569. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8570. c++;
  8571. }
  8572. sstr[c] = '\0';
  8573. strcpy(chargingRateUnitStr,sstr);
  8574. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8575. {
  8576. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8577. }
  8578. else
  8579. {
  8580. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8581. }
  8582. }
  8583. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8584. //****************chargingSchedulePeriod count start*******************/
  8585. int what_len = strlen("startPeriod");
  8586. char tempChargingProfile[1600]={0};
  8587. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8588. char *where = tempChargingProfile;
  8589. if (what_len)
  8590. {
  8591. while ((where = strstr(where, "startPeriod"))) {
  8592. where += what_len;
  8593. chargingSchedulePeriodCount++;
  8594. }
  8595. }
  8596. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8597. {
  8598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8599. goto end;
  8600. }
  8601. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8602. //where = payload;
  8603. int templength = 0;
  8604. //int searchstart = 0;
  8605. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8606. {
  8607. //****************startPeriod*******************/
  8608. c=0;
  8609. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8610. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8611. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8612. {
  8613. sstr[c] = loc[strlen("startPeriod")+2+c];
  8614. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8615. c++;
  8616. }
  8617. sstr[c] = '\0';
  8618. startPeriodInt[periodNums] = atoi(sstr);
  8619. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8620. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8621. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8622. {
  8623. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8624. }
  8625. else
  8626. {
  8627. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8628. }
  8629. templength = strlen("startPeriod")+2+c;
  8630. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8631. //****************limit*******************/
  8632. c=0;
  8633. loc = strstr(tempChargingProfile + templength, "limit");
  8634. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8635. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8636. {
  8637. sstr[c] = loc[strlen("limit")+2+c];
  8638. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8639. c++;
  8640. }
  8641. sstr[c] = '\0';
  8642. limitflaot[periodNums] = atof(sstr);
  8643. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8644. {
  8645. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8646. }
  8647. else
  8648. {
  8649. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8650. }
  8651. templength = templength + strlen("limit")+2+c;
  8652. //****************numberPhases*******************/
  8653. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8654. if(loc != NULL)
  8655. {
  8656. c=0;
  8657. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8658. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8659. {
  8660. sstr[c] = loc[strlen("numberPhases")+2+c];
  8661. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8662. c++;
  8663. }
  8664. sstr[c] = '\0';
  8665. numberPhasesInt[periodNums] = atoi(sstr);
  8666. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8667. {
  8668. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8669. }
  8670. else
  8671. {
  8672. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8673. }
  8674. templength = templength + strlen("numberPhases")+2+c;
  8675. }
  8676. //where = loc;
  8677. }
  8678. //****************chargingSchedulePeriod count end*******************/
  8679. //*********************minChargingRate***************************/
  8680. loc = strstr(sstrtemp, "minChargingRate");
  8681. if(loc != NULL)
  8682. {
  8683. c = 0;
  8684. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8685. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8686. {
  8687. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8688. c++;
  8689. }
  8690. sstr[c] = '\0';
  8691. minChargingRateFloat = atof(sstr);
  8692. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8693. {
  8694. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8695. }
  8696. else
  8697. {
  8698. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8699. }
  8700. }
  8701. else
  8702. {
  8703. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8704. {
  8705. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8706. }
  8707. else
  8708. {
  8709. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8710. }
  8711. }
  8712. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8713. {
  8714. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8715. if(connectorIdInt != 0)
  8716. {
  8717. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8718. goto end;
  8719. }
  8720. strcpy(filename, ChargePointMaxProfile_JSON );
  8721. fptr1 = fopen(filename, "r");
  8722. if (!fptr1)
  8723. {
  8724. //file not exist
  8725. DEBUG_INFO("Unable to open the input file!!\n");
  8726. fptr1 = fopen(filename, "w+");
  8727. }
  8728. else
  8729. {
  8730. //Check Charging Profile Count
  8731. while(fscanf(fptr1, "%s", word) != EOF)
  8732. {
  8733. //DEBUG_INFO("word=%s\n",word);
  8734. if(strstr(word, "chargingProfileId")!= NULL)
  8735. {
  8736. //DEBUG_INFO("test chargingProfileId \n");
  8737. n_chargingProfile = n_chargingProfile + 1;
  8738. //DEBUG_INFO("chargingProfileId Found\n");
  8739. }
  8740. }
  8741. }
  8742. fclose(fptr1);
  8743. }
  8744. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8745. {
  8746. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8747. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8748. {
  8749. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8750. goto end;
  8751. }
  8752. memset(filename, 0, ARRAY_SIZE(filename));
  8753. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8754. fptr1 = fopen(filename, "r");
  8755. if (!fptr1)
  8756. {
  8757. //file not exist
  8758. //DEBUG_INFO("Unable to open the input file!!\n");
  8759. fptr1 = fopen(filename, "w+");
  8760. }
  8761. else
  8762. {
  8763. //Check Charging Profile Count
  8764. while(fscanf(fptr1, "%s", word) != EOF)
  8765. {
  8766. //DEBUG_INFO("word=%s\n",word);
  8767. if(strstr(word, "chargingProfileId")!= NULL)
  8768. {
  8769. //DEBUG_INFO("test chargingProfileId \n");
  8770. n_chargingProfile = n_chargingProfile + 1;
  8771. //DEBUG_INFO("chargingProfileId Found\n");
  8772. }
  8773. }
  8774. }
  8775. fclose(fptr1);
  8776. }
  8777. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8778. {
  8779. //printf("set chargingProfile 1-4\n");
  8780. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8781. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8782. if(connectorIdInt == 0)
  8783. {
  8784. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8785. goto end;
  8786. }
  8787. int tempIndex = 0;
  8788. //check Transaction active
  8789. if(gunType[connectorIdInt -1] == 'J')
  8790. {
  8791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8792. {
  8793. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8794. }
  8795. else
  8796. {
  8797. tempIndex = connectorIdInt -1;
  8798. }
  8799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8800. {
  8801. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8802. {
  8803. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8804. {
  8805. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8806. {
  8807. meet = TRUE;
  8808. break;
  8809. }
  8810. }
  8811. }
  8812. }
  8813. }
  8814. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8815. {
  8816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8817. {
  8818. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8819. }
  8820. else
  8821. {
  8822. tempIndex = connectorIdInt -1;
  8823. }
  8824. for (int index = 0; index < CCS_QUANTITY; index++)
  8825. {
  8826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8827. {
  8828. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8829. {
  8830. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8831. {
  8832. meet = TRUE;
  8833. break;
  8834. }
  8835. }
  8836. }
  8837. }
  8838. }
  8839. else if(gunType[connectorIdInt -1] == 'G')
  8840. {
  8841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8842. {
  8843. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8844. }
  8845. else
  8846. {
  8847. tempIndex = connectorIdInt -1;
  8848. }
  8849. for (int index = 0; index < GB_QUANTITY; index++)
  8850. {
  8851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8852. {
  8853. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8854. {
  8855. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8856. {
  8857. meet = TRUE;
  8858. break;
  8859. }
  8860. }
  8861. }
  8862. }
  8863. }
  8864. else
  8865. {
  8866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8867. {
  8868. tempIndex = 2;
  8869. }
  8870. else
  8871. {
  8872. tempIndex = (connectorIdInt -1);
  8873. }
  8874. for (int index = 0; index < AC_QUANTITY; index++)
  8875. {
  8876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8877. {
  8878. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8879. {
  8880. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8881. {
  8882. meet = TRUE;
  8883. break;
  8884. }
  8885. }
  8886. }
  8887. }
  8888. }
  8889. //check Transaction active
  8890. if(meet == FALSE)
  8891. {
  8892. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8893. goto end;
  8894. }
  8895. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8896. {
  8897. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8898. goto end;
  8899. }
  8900. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8901. fptr1 = fopen(filename, "r");
  8902. if (!fptr1)
  8903. {
  8904. //file not exist
  8905. DEBUG_INFO("Unable to open the input file!!\n");
  8906. fptr1 = fopen(filename, "w+");
  8907. }
  8908. else
  8909. {
  8910. //Check Charging Profile Count
  8911. while(fscanf(fptr1, "%s", word) != EOF)
  8912. {
  8913. //DEBUG_INFO("word=%s\n",word);
  8914. if(strstr(word, "chargingProfileId")!= NULL)
  8915. {
  8916. //DEBUG_INFO("test chargingProfileId \n");
  8917. n_chargingProfile = n_chargingProfile + 1;
  8918. //DEBUG_INFO("chargingProfileId Found\n");
  8919. }
  8920. }
  8921. }
  8922. fclose(fptr1);
  8923. }
  8924. // Check ChargeProfileMaxStackLevel
  8925. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8926. {
  8927. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8928. goto end;
  8929. }
  8930. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8931. {
  8932. int i = 0;
  8933. char fnametemp[200]={0};
  8934. n_chargingProfile = 0;
  8935. //Check ChargePointMaxProfile.json exit
  8936. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8937. {
  8938. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8939. //Check Charging Profile Count
  8940. while(fscanf(fptr1, "%s", word) != EOF)
  8941. {
  8942. //DEBUG_INFO("word=%s\n",word);
  8943. if(strstr(word, "chargingProfileId")!= NULL)
  8944. {
  8945. //DEBUG_INFO("test chargingProfileId \n");
  8946. n_chargingProfile = n_chargingProfile + 1;
  8947. i = i + 1;
  8948. //DEBUG_INFO("chargingProfileId Found\n");
  8949. }
  8950. memset(word, 0, ARRAY_SIZE(word));
  8951. }
  8952. fclose(fptr1);
  8953. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8954. }
  8955. //Check TxDefaultProfile_0.json exit
  8956. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8957. {
  8958. i = 0;
  8959. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8960. //Check Charging Profile Count
  8961. while(fscanf(fptr1, "%s", word) != EOF)
  8962. {
  8963. //DEBUG_INFO("word=%s\n",word);
  8964. if(strstr(word, "chargingProfileId")!= NULL)
  8965. {
  8966. //DEBUG_INFO("test chargingProfileId \n");
  8967. n_chargingProfile = n_chargingProfile + 1;
  8968. i = i + 1;
  8969. //DEBUG_INFO("chargingProfileId Found\n");
  8970. }
  8971. memset(word, 0, ARRAY_SIZE(word));
  8972. }
  8973. fclose(fptr1);
  8974. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8975. }
  8976. //Check TxDefaultProfile_%d.json
  8977. for(int j=1; j <= gunTotalNumber; j++)
  8978. {
  8979. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8980. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8981. if((access(fnametemp,F_OK))!=-1)
  8982. {
  8983. i = 0;
  8984. fptr1 = fopen(fnametemp, "r");
  8985. //Check Charging Profile Count
  8986. while(fscanf(fptr1, "%s", word) != EOF)
  8987. {
  8988. //DEBUG_INFO("word=%s\n",word);
  8989. if(strstr(word, "chargingProfileId")!= NULL)
  8990. {
  8991. //DEBUG_INFO("test chargingProfileId \n");
  8992. n_chargingProfile = n_chargingProfile + 1;
  8993. i = i + 1;
  8994. //DEBUG_INFO("chargingProfileId Found\n");
  8995. }
  8996. memset(word, 0, ARRAY_SIZE(word));
  8997. }
  8998. fclose(fptr1);
  8999. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9000. }
  9001. }
  9002. //Check TxProfile_%d.json
  9003. for(int j=1; j <= gunTotalNumber; j++)
  9004. {
  9005. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9006. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9007. if((access(fnametemp,F_OK))!=-1)
  9008. {
  9009. i = 0;
  9010. fptr1 = fopen(fnametemp, "r");
  9011. //Check Charging Profile Count
  9012. while(fscanf(fptr1, "%s", word) != EOF)
  9013. {
  9014. //DEBUG_INFO("word=%s\n",word);
  9015. if(strstr(word, "chargingProfileId")!= NULL)
  9016. {
  9017. //DEBUG_INFO("test chargingProfileId \n");
  9018. n_chargingProfile = n_chargingProfile + 1;
  9019. i = i + 1;
  9020. //DEBUG_INFO("chargingProfileId Found\n");
  9021. }
  9022. memset(word, 0, ARRAY_SIZE(word));
  9023. }
  9024. fclose(fptr1);
  9025. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9026. }
  9027. }
  9028. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9029. {
  9030. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9031. goto end;
  9032. }
  9033. }
  9034. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9035. //**********************************Write to File********************************************************/
  9036. FILE *infile;
  9037. FILE *outfile;
  9038. // open file for writing
  9039. infile = fopen (filename, "r");
  9040. outfile = fopen (tempfile, "w");
  9041. int d =0;
  9042. d = fgetc(infile);
  9043. //DEBUG_INFO("d:%d\n",d);
  9044. rewind(infile);
  9045. //*璉 瘚 辣蝏     1嚗   0 */
  9046. if(d == EOF)
  9047. {
  9048. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9049. fprintf(outfile,"%s\n",payload);
  9050. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9051. fclose(infile);
  9052. fclose(outfile);
  9053. sprintf(rmFileCmd,"rm -f %s",filename);
  9054. system(rmFileCmd);
  9055. rename(tempfile, filename);
  9056. sleep(1);
  9057. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9058. //system(rmFileCmd);
  9059. }
  9060. else
  9061. {
  9062. char buf[1000]={0};
  9063. int ChargingProfileAdded = FALSE;
  9064. while (fgets(buf, sizeof(buf), infile) != NULL)
  9065. {
  9066. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9067. //*************************tempconnectorIdInt*********************************/
  9068. loc = strstr(buf, "connectorId");
  9069. c = 0;
  9070. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9071. while (loc[strlen("connectorId")+2+c] != ',')
  9072. {
  9073. sstr[c] = loc[strlen("connectorId")+2+c];
  9074. c++;
  9075. }
  9076. sstr[c] = '\0';
  9077. tempconnectorIdInt = atoi(sstr);
  9078. //*************************tempchargingProfileIdInt*********************************/
  9079. loc = strstr(buf, "chargingProfileId");
  9080. c = 0;
  9081. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9082. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9083. {
  9084. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9085. c++;
  9086. }
  9087. sstr[c] = '\0';
  9088. tempchargingProfileIdInt = atoi(sstr);
  9089. //*************************tempstackLevelInt*********************************/
  9090. loc = strstr(buf, "stackLevel");
  9091. c = 0;
  9092. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9093. while (loc[strlen("stackLevel")+2+c] != ',')
  9094. {
  9095. sstr[c] = loc[strlen("stackLevel")+2+c];
  9096. c++;
  9097. }
  9098. sstr[c] = '\0';
  9099. tempstackLevelInt = atoi(sstr);
  9100. //*************************tempchargingProfilePurposeStr*********************************/
  9101. loc = strstr(payload, "chargingProfilePurpose");
  9102. c = 0;
  9103. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9104. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9105. {
  9106. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9108. c++;
  9109. }
  9110. sstr[c] = '\0';
  9111. strcpy(tempchargingProfilePurposeStr,sstr);
  9112. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9113. {
  9114. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9115. {
  9116. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9117. if(ChargingProfileAdded == FALSE)
  9118. {
  9119. fprintf(outfile,"%s\n",payload);
  9120. ChargingProfileAdded = TRUE;
  9121. }
  9122. }
  9123. else
  9124. {
  9125. if(tempstackLevelInt < stackLevelInt)
  9126. {
  9127. if(ChargingProfileAdded == FALSE)
  9128. {
  9129. fprintf(outfile,"%s\n",payload);
  9130. ChargingProfileAdded = TRUE;
  9131. fprintf(outfile,"%s\n",buf);
  9132. }
  9133. else
  9134. {
  9135. fprintf(outfile,"%s\n",buf);
  9136. }
  9137. }
  9138. else
  9139. {
  9140. if(ChargingProfileAdded == FALSE)
  9141. {
  9142. fprintf(outfile,"%s\n",buf);
  9143. fprintf(outfile,"%s\n",payload);
  9144. ChargingProfileAdded = TRUE;
  9145. }
  9146. else
  9147. {
  9148. fprintf(outfile,"%s\n",buf);
  9149. }
  9150. }
  9151. }
  9152. }
  9153. else
  9154. {
  9155. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9156. {
  9157. if(ChargingProfileAdded == FALSE)
  9158. {
  9159. fprintf(outfile,"%s\n",payload);
  9160. ChargingProfileAdded = TRUE;
  9161. fprintf(outfile,"%s\n",buf);
  9162. }
  9163. else
  9164. {
  9165. fprintf(outfile,"%s\n",buf);
  9166. }
  9167. }
  9168. else if(tempstackLevelInt < stackLevelInt)
  9169. {
  9170. if(ChargingProfileAdded == FALSE)
  9171. {
  9172. fprintf(outfile,"%s\n",payload);
  9173. ChargingProfileAdded = TRUE;
  9174. fprintf(outfile,"%s\n",buf);
  9175. }
  9176. else
  9177. {
  9178. fprintf(outfile,"%s\n",buf);
  9179. }
  9180. }
  9181. else
  9182. {
  9183. if(ChargingProfileAdded == FALSE)
  9184. {
  9185. fprintf(outfile,"%s\n",buf);
  9186. fprintf(outfile,"%s\n",payload);
  9187. ChargingProfileAdded = TRUE;
  9188. }
  9189. else
  9190. {
  9191. fprintf(outfile,"%s\n",buf);
  9192. }
  9193. }
  9194. }
  9195. } // end of while loop
  9196. fclose(infile);
  9197. fclose(outfile);
  9198. sprintf(rmFileCmd,"rm -f %s",filename);
  9199. system(rmFileCmd);
  9200. rename(tempfile, filename);
  9201. sleep(1);
  9202. result = TRUE;
  9203. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9204. }
  9205. end:
  9206. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9207. return result;
  9208. return result;
  9209. }
  9210. int handleTriggerMessageRequest(char *uuid, char *payload)
  9211. {
  9212. mtrace();
  9213. int result = FAIL;
  9214. int connectorIdIsNULL = FALSE;
  9215. int connectorIdInt =0;
  9216. char sstr[40]={0},sstrtemp[100]={ 0 };
  9217. char requestedMessagestr[40]={0};
  9218. char comfirmstr[20]={0};
  9219. int c = 0;
  9220. char *loc;
  9221. DEBUG_INFO("handleTriggerMessageRequest\n");
  9222. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9223. strcpy(sstrtemp, stringtrimspace(payload));
  9224. c = 0;
  9225. loc = strstr(sstrtemp, "requestedMessage");
  9226. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9227. {
  9228. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9229. c++;
  9230. }
  9231. sstr[c] = '\0';
  9232. strcpy(requestedMessagestr, sstr);
  9233. c = 0;
  9234. loc = strstr(sstrtemp, "connectorId");
  9235. if(loc == NULL)
  9236. {
  9237. connectorIdIsNULL = TRUE;
  9238. }
  9239. else
  9240. {
  9241. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9242. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9243. {
  9244. sstr[c] = loc[strlen("connectorId")+2+c];
  9245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9246. c++;
  9247. }
  9248. sstr[c] = '\0';
  9249. connectorIdInt = atoi(sstr);
  9250. }
  9251. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9252. {
  9253. //connectorIdInt = json_object_get_int(connectorId);
  9254. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9255. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9256. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9257. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9258. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9259. }
  9260. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9261. {
  9262. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9263. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9264. return TRUE;
  9265. }
  9266. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9267. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9268. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9269. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9270. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9271. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9272. {
  9273. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9274. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9275. return TRUE;
  9276. }
  9277. else
  9278. {
  9279. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9280. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9281. }
  9282. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9283. {
  9284. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9285. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9286. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9287. {
  9288. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9289. }
  9290. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9291. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9292. }
  9293. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9294. {
  9295. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9296. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9297. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9298. }
  9299. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9300. {
  9301. sendBootNotificationRequest();
  9302. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9303. }
  9304. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9305. {
  9306. sendHeartbeatRequest(connectorIdInt);
  9307. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9308. }
  9309. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9310. {
  9311. if(connectorIdIsNULL == FALSE)
  9312. {
  9313. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9314. {
  9315. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9316. sendMeterValuesRequest(connectorIdInt -1);
  9317. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9318. }
  9319. }
  9320. else
  9321. {
  9322. for(int idx=0;idx< gunTotalNumber;idx++)
  9323. {
  9324. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9325. sendMeterValuesRequest(idx);
  9326. }
  9327. }
  9328. }
  9329. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9330. {
  9331. if(connectorIdIsNULL == FALSE)
  9332. {
  9333. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9334. {
  9335. sendStatusNotificationRequest(connectorIdInt -1);
  9336. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9337. }
  9338. }
  9339. else
  9340. {
  9341. for(int idx=0;idx< gunTotalNumber;idx++)
  9342. sendStatusNotificationRequest(idx);
  9343. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9344. }
  9345. }
  9346. return result;
  9347. }
  9348. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9349. {
  9350. mtrace();
  9351. int result = FAIL;
  9352. char sstr[6]={0},sstrtemp[50]={ 0 };
  9353. int connectorIdInt =0;
  9354. char comfirmstr[20]={0};
  9355. int c = 0;
  9356. int tempIndex = 0;
  9357. char *loc;
  9358. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9359. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9360. strcpy(sstrtemp, stringtrimspace(payload));
  9361. c = 0;
  9362. loc = strstr(sstrtemp, "connectorId");
  9363. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9364. while (loc[strlen("connectorId")+2+c] != '}')
  9365. {
  9366. sstr[c] = loc[strlen("connectorId")+2+c];
  9367. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9368. c++;
  9369. }
  9370. sstr[c] = '\0';
  9371. connectorIdInt = atoi(sstr);
  9372. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9373. if(gunTotalNumber == 0)
  9374. {
  9375. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9376. goto end;
  9377. }
  9378. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9379. {
  9380. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9381. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9382. goto end;
  9383. }
  9384. else
  9385. {
  9386. //check Transaction active
  9387. if(gunType[connectorIdInt-1] == 'J')
  9388. {
  9389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9390. {
  9391. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9392. }
  9393. else
  9394. {
  9395. tempIndex = connectorIdInt -1;
  9396. }
  9397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9398. {
  9399. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9400. {
  9401. //stop Transaction
  9402. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9403. }
  9404. }
  9405. }
  9406. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9407. {
  9408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9409. {
  9410. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9411. }
  9412. else
  9413. {
  9414. tempIndex = connectorIdInt -1;
  9415. }
  9416. for (int index = 0; index < CCS_QUANTITY; index++)
  9417. {
  9418. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9419. {
  9420. //stop Transaction
  9421. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9422. }
  9423. }
  9424. }
  9425. else if(gunType[connectorIdInt-1] == 'G')
  9426. {
  9427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9428. {
  9429. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9430. }
  9431. else
  9432. {
  9433. tempIndex = connectorIdInt -1;
  9434. }
  9435. for (int index = 0; index < GB_QUANTITY; index++)
  9436. {
  9437. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9438. {
  9439. //stop Transaction
  9440. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9441. }
  9442. }
  9443. }
  9444. else
  9445. {
  9446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9447. {
  9448. tempIndex = 2;
  9449. }
  9450. else
  9451. {
  9452. tempIndex = connectorIdInt-1;
  9453. }
  9454. for (int index = 0; index < AC_QUANTITY; index++)
  9455. {
  9456. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9457. {
  9458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9459. }
  9460. }
  9461. }
  9462. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9463. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9464. result = TRUE;
  9465. return result;
  9466. }
  9467. end:
  9468. //json_object_put(obj); --- remove temporally
  9469. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9470. return result;
  9471. }
  9472. static char UpdateFirmwarepayloadData[300]={0};
  9473. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9474. {
  9475. mtrace();
  9476. int result = FAIL;
  9477. pthread_t t;
  9478. sendUpdateFirmwareConfirmation(uuid);
  9479. memset(UpdateFirmwarepayloadData, 0, 300);
  9480. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9481. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9482. ////pthread_join(t, NULL); //
  9483. //pthread_detach(t);
  9484. //sendUpdateFirmwareConfirmation(uuid);
  9485. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9486. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9487. return result;
  9488. }
  9489. void *UpdateFirmwareProcess(void *data)
  9490. {
  9491. pthread_detach(pthread_self());
  9492. mtrace();
  9493. int retriesInt =0, retryIntervalInt=0;
  9494. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9495. int port=0;
  9496. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9497. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9498. //char comfirmstr[20];
  9499. int isSuccess = 0;
  9500. char ftpbuf[200];
  9501. char temp[100];
  9502. char * pch;
  9503. int retriesISNULL=FALSE;
  9504. int retryInterval=FALSE;
  9505. int c = 0;
  9506. //int i = 0;
  9507. char *loc;
  9508. char sstr[300]={ 0 };
  9509. char str[300]={ 0 };
  9510. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9511. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9512. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9513. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9514. //***************location **************/
  9515. loc = strstr(str, "location");
  9516. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9517. c = 0;
  9518. while (loc[3+strlen("location")+c] != '\"')
  9519. {
  9520. sstr[c] = loc[3+strlen("location")+c];
  9521. c++;
  9522. }
  9523. sstr[c] = '\0';
  9524. strcpy(locationstr, sstr);
  9525. //***************retries**************/
  9526. c = 0;
  9527. loc = strstr(str, "retries");
  9528. if(loc == NULL)
  9529. {
  9530. retriesISNULL=TRUE;
  9531. }
  9532. else
  9533. {
  9534. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9535. while (loc[strlen("retries")+2+c] != ',')
  9536. {
  9537. sstr[c] = loc[strlen("retries")+2+c];
  9538. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9539. c++;
  9540. }
  9541. sstr[c] = '\0';
  9542. }
  9543. if(retriesISNULL == FALSE)
  9544. {
  9545. retriesInt = atoi(sstr);
  9546. }
  9547. //***************retrieveDate **************/
  9548. loc = strstr(str, "retrieveDate");
  9549. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9550. c = 0;
  9551. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9552. {
  9553. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9554. c++;
  9555. }
  9556. sstr[c] = '\0';
  9557. strcpy(retrieveDatestr, sstr);
  9558. //***************retryInterval **************/
  9559. c = 0;
  9560. loc = strstr(str, "retryInterval");
  9561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9562. if(loc == NULL)
  9563. {
  9564. retryInterval=TRUE;
  9565. }
  9566. else
  9567. {
  9568. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9569. {
  9570. sstr[c] = loc[strlen("retryInterval")+2+c];
  9571. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9572. c++;
  9573. }
  9574. sstr[c] = '\0';
  9575. }
  9576. if(retryInterval==FALSE)
  9577. {
  9578. retryIntervalInt = atoi(sstr);
  9579. }
  9580. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9581. memset(path, 0, ARRAY_SIZE(path));
  9582. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9583. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9584. if(strncmp(locationstr,"http", 4) == 0)
  9585. {
  9586. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9587. protocol, host, path);
  9588. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9589. // protocol, user, password, host, path);
  9590. sprintf(ftppath,"/%s", path);
  9591. //DEBUG_INFO("protocol =%s\n",protocol);
  9592. //DEBUG_INFO("host =%s\n",host);
  9593. //DEBUG_INFO("path =%s\n",path);
  9594. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9595. int ftppathlen=strlen(ftppath);
  9596. int i=1;
  9597. char filenametemp[50];
  9598. while(i < ftppathlen)
  9599. {
  9600. int len=ftppathlen-i;
  9601. if(ftppath[len]== 47) // '/' ascll code: 47
  9602. {
  9603. DEBUG_INFO("compare '/' all right\n");
  9604. break;
  9605. }
  9606. i=i+1;
  9607. }
  9608. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9609. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9610. filenametemp[i+1] = 0;
  9611. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9612. do{
  9613. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9614. sleep(retryIntervalInt);
  9615. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9616. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9617. if(!isSuccess)
  9618. {
  9619. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9620. }
  9621. else
  9622. {
  9623. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9624. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9625. //isUpdateRequest = TRUE;
  9626. }
  9627. }
  9628. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9629. {
  9630. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9631. memset(temp, 0, ARRAY_SIZE(temp));
  9632. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9633. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9634. int ftppathlen=strlen(ftpbuf);
  9635. int i=1;
  9636. char filenametemp[50];
  9637. while(i < ftppathlen)
  9638. {
  9639. int len=ftppathlen-i;
  9640. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9641. {
  9642. DEBUG_INFO(" compare '/' all right\n");
  9643. break;
  9644. }
  9645. i=i+1;
  9646. }
  9647. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9648. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9649. filenametemp[i+1] = 0;
  9650. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9651. pch=strchr(temp,'@');
  9652. if(pch==NULL)
  9653. {
  9654. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9655. protocol, host, &port, path);
  9656. strcpy(user,"anonymous");
  9657. strcpy(password,"");
  9658. }
  9659. else
  9660. {
  9661. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9662. protocol, user, password, host, &port, path);
  9663. }
  9664. sscanf(host,"%[^/]%s",host1, path1);
  9665. sprintf(ftppath,"%s", path1);
  9666. //DEBUG_INFO("protocol =%s\n",protocol);
  9667. //DEBUG_INFO("user =%s\n",user);
  9668. //DEBUG_INFO("password =%s\n",password);
  9669. //DEBUG_INFO("host1 =%s\n",host1);
  9670. //DEBUG_INFO("port =%d\n",port);
  9671. //DEBUG_INFO("path1 =%s\n",path1);
  9672. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9673. //ftpFile(host, user, password, port, ftppath, fname);
  9674. //download firmware pthred
  9675. if(port == 0)
  9676. {
  9677. port = 21;
  9678. }
  9679. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9680. do{
  9681. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9682. sleep(retryIntervalInt);
  9683. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9684. if(!isSuccess)
  9685. {
  9686. //BulldogUtil.sleepMs(interval*1000);
  9687. DEBUG_INFO("Update firmware request and download file fail.\n");
  9688. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9689. }
  9690. else
  9691. {
  9692. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9693. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9694. //isUpdateRequest = TRUE;
  9695. }
  9696. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9697. }
  9698. else
  9699. {
  9700. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9701. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9702. }
  9703. pthread_exit(NULL);
  9704. }
  9705. //==========================================
  9706. // Handle server response routine
  9707. //==========================================
  9708. void handleAuthorizeResponse(char *payload, int gun_index)
  9709. {
  9710. mtrace();
  9711. char expiryDatestr[30]={0};
  9712. char parentIdTagstr[20]={0};
  9713. char statusstr[20]={0};
  9714. char expiryDatestrtemp[30]={0};
  9715. char parentIdTagstrtemp[20]={0};
  9716. char IdTagstrtemp[20]={0};
  9717. char statusstrtemp[20]={0};
  9718. int expiryDateISNULL=FALSE;
  9719. int parentIdTagISNULL=FALSE;
  9720. char sstr[160]={0};
  9721. char* filename = AuthorizationCache_JSON;
  9722. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9723. char *loc;
  9724. int resultRename=0;
  9725. int responseIdTagInfoAsZero= 0;
  9726. char rmFileCmd[50]={0};
  9727. DEBUG_INFO("handleAuthorizeResponse...\n");
  9728. json_object *Authorize;
  9729. Authorize = json_tokener_parse(payload);
  9730. if(!is_error(Authorize))
  9731. {
  9732. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9733. {
  9734. // Required data
  9735. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9736. // Optional data
  9737. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9738. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9739. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9740. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9741. }
  9742. }
  9743. json_object_put(Authorize);
  9744. if(expiryDateISNULL == FALSE)
  9745. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9746. if(parentIdTagISNULL == FALSE)
  9747. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9748. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9749. //Update idTag information to authorization cache if supproted
  9750. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9751. {
  9752. if((access(filename,F_OK))!=-1)
  9753. {
  9754. printf("AuthorizationCache exist.\n");
  9755. }
  9756. else
  9757. {
  9758. printf("AuthorizationCache not exist\n");
  9759. FILE *log = fopen(filename, "w+");
  9760. if(log == NULL)
  9761. {
  9762. printf("log is NULL\n");
  9763. goto out;
  9764. }
  9765. else
  9766. {
  9767. fclose(log);
  9768. }
  9769. }
  9770. FILE *infile;
  9771. FILE *outfile;
  9772. // open file for writing
  9773. infile = fopen (filename, "r");
  9774. outfile = fopen (tempfile, "w");
  9775. int c;
  9776. c = fgetc(infile);
  9777. //DEBUG_INFO("c:%d\n",c);
  9778. rewind(infile);
  9779. if(c == EOF)
  9780. {
  9781. DEBUG_INFO("Orignal File is NULL\n");
  9782. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9783. {
  9784. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9785. }
  9786. else
  9787. {
  9788. strcpy(expiryDatestrtemp, "");
  9789. }
  9790. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9791. {
  9792. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9793. }
  9794. else
  9795. {
  9796. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9797. }
  9798. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9799. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9800. fclose(infile);
  9801. fclose(outfile);
  9802. sprintf(rmFileCmd,"rm -f %s",filename);
  9803. system(rmFileCmd);
  9804. resultRename = rename(tempfile, filename);
  9805. if(resultRename == 0)
  9806. {
  9807. printf("File renamed successfully");
  9808. }
  9809. else
  9810. {
  9811. printf("Error: unable to rename the file");
  9812. }
  9813. }
  9814. else
  9815. {
  9816. char buf[160]={0};
  9817. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9818. {
  9819. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9820. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9821. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9822. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9823. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9824. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9825. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9826. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9827. //------------------IdTag-----------------------
  9828. loc = strstr(buf, "idTag");
  9829. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9830. c = 0;
  9831. while (loc[3+strlen("idTag")+c] != '\"')
  9832. {
  9833. sstr[c] = loc[3+strlen("idTag")+c];
  9834. c++;
  9835. }
  9836. sstr[c] = '\0';
  9837. strcpy(IdTagstrtemp,sstr);
  9838. //*********************expiryDate***************/
  9839. loc = strstr(buf, "expiryDate");
  9840. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9841. c = 0;
  9842. while (loc[3+strlen("expiryDate")+c] != '\"')
  9843. {
  9844. sstr[c] = loc[3+strlen("expiryDate")+c];
  9845. c++;
  9846. }
  9847. sstr[c] = '\0';
  9848. strcpy(expiryDatestr,sstr);
  9849. //*********************parentIdTag***************/
  9850. loc = strstr(buf, "parentIdTag");
  9851. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9852. c = 0;
  9853. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9854. {
  9855. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9856. c++;
  9857. }
  9858. sstr[c] = '\0';
  9859. strcpy(parentIdTagstr,sstr);
  9860. //*********************status***************/
  9861. loc = strstr(buf, "status");
  9862. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9863. c = 0;
  9864. while (loc[3+strlen("status")+c] != '\"')
  9865. {
  9866. sstr[c] = loc[3+strlen("status")+c];
  9867. c++;
  9868. }
  9869. sstr[c] = '\0';
  9870. strcpy(statusstr,sstr);
  9871. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9872. {
  9873. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9874. responseIdTagInfoAsZero = 1;
  9875. }
  9876. else
  9877. {
  9878. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9879. }
  9880. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9881. {
  9882. //modify item
  9883. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9884. {
  9885. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9886. }
  9887. else
  9888. {
  9889. strcpy(expiryDatestrtemp, "");
  9890. }
  9891. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9892. {
  9893. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9894. }
  9895. else
  9896. {
  9897. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9898. }
  9899. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9900. }
  9901. else
  9902. {
  9903. //wrie original item
  9904. strcpy(expiryDatestrtemp, expiryDatestr);
  9905. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9906. strcpy(statusstrtemp, statusstr);
  9907. }
  9908. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9909. }
  9910. fclose(infile);
  9911. fclose(outfile);
  9912. sprintf(rmFileCmd,"rm -f %s",filename);
  9913. system(rmFileCmd);
  9914. resultRename = rename(tempfile, filename);
  9915. if(resultRename == 0)
  9916. {
  9917. DEBUG_INFO("File renamed successfully");
  9918. }
  9919. else
  9920. {
  9921. DEBUG_INFO("Error: unable to rename the file");
  9922. }
  9923. }
  9924. }
  9925. out:
  9926. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9927. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9928. authorizeRetryTimes = 0;
  9929. }
  9930. char * strtrimc( char * s )
  9931. {
  9932. char * p1 = s;
  9933. char * p2 = s;
  9934. while(*p1 != '\0')
  9935. {
  9936. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9937. {
  9938. if(*p1 != ',')
  9939. {
  9940. p1 ++;
  9941. }
  9942. else
  9943. {
  9944. break;
  9945. }
  9946. }
  9947. if(*p1 != ',')
  9948. {
  9949. * p2 ++ = *p1 ++;
  9950. //printf("p2=%s\n",p2);
  9951. }
  9952. else
  9953. {
  9954. break;
  9955. }
  9956. }
  9957. *p2 = '\0';
  9958. return (s);
  9959. }
  9960. void handleBootNotificationResponse(char *payload, int gun_index)
  9961. {
  9962. mtrace();
  9963. char statusStr[12]={0};
  9964. char currentTimeStr[30]={0};
  9965. int intervalInt = 0;
  9966. struct tm tp;
  9967. char buf[28]={0};
  9968. char timebuf[50]={0};
  9969. DEBUG_INFO("handleBootNotificationResponse...\n");
  9970. json_object *BootNotification;
  9971. BootNotification = json_tokener_parse(payload);
  9972. if(!is_error(BootNotification))
  9973. {
  9974. // Required data
  9975. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9976. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9977. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9978. }
  9979. json_object_put(BootNotification);
  9980. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9981. BootNotificationInterval = intervalInt;
  9982. HeartBeatWaitTime = intervalInt;
  9983. //write back to ShmOCPP16Data->BootNotification
  9984. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9985. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9986. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9987. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9988. {
  9989. server_sign = TRUE;
  9990. server_pending =FALSE;
  9991. }
  9992. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9993. {
  9994. server_pending = TRUE;
  9995. }
  9996. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9997. tp.tm_isdst = -1;
  9998. //time_t utc = mktime(&tp);
  9999. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10000. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10001. sprintf(timebuf,"date -s '%s'",buf);
  10002. system(timebuf);
  10003. srand(time(NULL));
  10004. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10005. //==============================================
  10006. // RTC sync
  10007. //==============================================
  10008. system("/sbin/hwclock -w --systohc");
  10009. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10010. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10011. }
  10012. void handleDataTransferResponse(char *payload, int gun_index)
  10013. {
  10014. char sstr[160]={0};//sstr[200]={ 0 };
  10015. int c = 0;
  10016. char *loc;
  10017. DEBUG_INFO("handleDataTransferResponse ...\n");
  10018. loc = strstr(payload, "status");
  10019. printf("loc=%s\n",loc);
  10020. c = 0;
  10021. while (loc[3+strlen("status")+c] != '\"')
  10022. {
  10023. sstr[c] = loc[3+strlen("status")+c];
  10024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10025. c++;
  10026. }
  10027. sstr[c] = '\0';
  10028. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10029. }
  10030. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10031. {
  10032. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10033. //struct json_object *obj;
  10034. // obj = json_tokener_parse(payload);
  10035. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10036. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10037. //No fields are defined.
  10038. }
  10039. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10040. {
  10041. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10042. //struct json_object *obj;
  10043. // obj = json_tokener_parse(payload);
  10044. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10045. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10046. //No fields are defined.
  10047. }
  10048. void handleHeartbeatResponse(char *payload, int gun_index)
  10049. {
  10050. mtrace();
  10051. struct tm tp;
  10052. char buf[28]={0};
  10053. char timebuf[50]={0};
  10054. DEBUG_INFO("handleHeartbeatResponse...\n");
  10055. json_object *Heartbeat;
  10056. Heartbeat = json_tokener_parse(payload);
  10057. if(!is_error(Heartbeat))
  10058. {
  10059. // Required data
  10060. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10061. }
  10062. json_object_put(BootNotification);
  10063. if(FirstHeartBeat == 0)
  10064. {
  10065. FirstHeartBeat = 1;
  10066. DEBUG_INFO("FirstHeartBeat \n");
  10067. }
  10068. HeartBeatWithNOResponse = 0;
  10069. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10070. tp.tm_isdst = -1;
  10071. //time_t utc = mktime(&tp);
  10072. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10073. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10074. sprintf(timebuf,"date -s '%s'",buf);
  10075. system(timebuf);
  10076. //==============================================
  10077. // RTC sync
  10078. //==============================================
  10079. system("/sbin/hwclock -w --systohc");
  10080. //===============================================
  10081. //Print Out HeartBeat log
  10082. //===============================================
  10083. {
  10084. double diff_t;
  10085. struct tm tp,tp1;
  10086. // BootNotification Receive Time
  10087. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10088. tp.tm_isdst = -1;
  10089. time_t BootNotificationReceiveTime = mktime(&tp);
  10090. //HeartBeat Receive Time
  10091. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10092. tp1.tm_isdst = -1;
  10093. time_t HeartBeatReceiveTime = mktime(&tp1);
  10094. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10095. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10096. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10097. {
  10098. HeartBeatCountPerHour = (int)diff_t / 3600;
  10099. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10100. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10101. }
  10102. }
  10103. }
  10104. void handleMeterValuesResponse(char *payload, int gun_index)
  10105. {
  10106. mtrace();
  10107. DEBUG_INFO("handleMeterValuesResponse...\n");
  10108. }
  10109. void handleStartTransactionResponse(char *payload, int gun_index)
  10110. {
  10111. mtrace();
  10112. //int transactionIdInt = 0;
  10113. FILE *outfile;
  10114. char data[100]={0};
  10115. DEBUG_INFO("handleStartTransactionResponse...\n");
  10116. json_object *StartTransaction;
  10117. StartTransaction = json_tokener_parse(payload);
  10118. if(!is_error(StartTransaction))
  10119. {
  10120. // Required data
  10121. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10122. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10123. // Optional data
  10124. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10125. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10126. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10127. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10128. }
  10129. json_object_put(StartTransaction);
  10130. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10131. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10132. //-----------Start : write to the Queue TransactionId file -----------------//
  10133. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10134. {}
  10135. else
  10136. {
  10137. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10138. if(log == NULL)
  10139. {
  10140. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10141. return ;
  10142. }
  10143. else
  10144. {
  10145. fclose(log);
  10146. }
  10147. }
  10148. // open file for writing
  10149. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10150. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10151. {
  10152. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10153. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10154. fputs(data, outfile);
  10155. fclose (outfile);
  10156. }
  10157. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10158. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10159. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10160. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10161. }
  10162. void handleStatusNotificationResponse(char *payload, int gun_index)
  10163. {
  10164. mtrace();
  10165. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10166. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10167. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10168. }
  10169. void handleStopTransactionnResponse(char *payload, int gun_index)
  10170. {
  10171. mtrace();
  10172. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10173. json_object *StopTransaction;
  10174. StopTransaction = json_tokener_parse(payload);
  10175. if(!is_error(StopTransaction))
  10176. {
  10177. // Optional data
  10178. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10179. {
  10180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10181. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10183. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10185. }
  10186. }
  10187. json_object_put(StopTransaction);
  10188. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10189. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10190. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10191. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10192. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10193. }
  10194. //==========================================
  10195. // Handle Error routine
  10196. //==========================================
  10197. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10198. {
  10199. mtrace();
  10200. #ifdef SystemLogMessage
  10201. DEBUG_INFO("errorCode: %s\n", errorCode);
  10202. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10203. DEBUG_INFO("errorDetails: %s\n", payload);
  10204. #endif
  10205. }
  10206. //===============================================
  10207. // Common routine
  10208. //===============================================
  10209. int initialConfigurationTable(void)
  10210. {
  10211. //clock_t start_t, end_t, total_t;
  10212. FILE *fp;
  10213. FILE *outfile;
  10214. char str[200]={0};
  10215. char sstr[100]={0};
  10216. int c = 0;
  10217. char *loc;
  10218. DEBUG_INFO("initialConfigurationTable...\n");
  10219. //start_t = clock();
  10220. //printf("Starting of the program, start_t = %ld\n", start_t);
  10221. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10222. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10223. {
  10224. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10225. if(outfile == NULL)
  10226. {
  10227. DEBUG_INFO("Error opening file\n");
  10228. return FALSE;
  10229. }
  10230. /*Core Profile*/
  10231. //AllowOfflineTxForUnknownId
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10233. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10237. //AuthorizationCacheEnabled
  10238. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10242. //AuthorizeRemoteTxRequests
  10243. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10247. //BlinkRepeat
  10248. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10252. //ClockAlignedDataInterval
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10257. //ConnectionTimeOut
  10258. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10262. //GetConfigurationMaxKeys
  10263. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10267. // HeartbeatInterval
  10268. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10272. // LightIntensity
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10277. // LocalAuthorizeOffline
  10278. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10282. // LocalPreAuthorize
  10283. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10287. // MaxEnergyOnInvalidId
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10291. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10293. // MeterValuesAlignedData
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10297. 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");
  10298. // MeterValuesAlignedDataMaxLength
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "6");
  10303. // MeterValuesSampledData
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10307. 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");
  10308. // MeterValuesSampledDataMaxLength
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10313. // MeterValueSampleInterval
  10314. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10318. // MinimumStatusDuration
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10322. server_cycle_Status = 120; //StatusNotification cycle
  10323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10324. // NumberOfConnectors
  10325. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10328. {
  10329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10330. }
  10331. else
  10332. {
  10333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10334. }
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10336. // ResetRetries
  10337. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10341. // ConnectorPhaseRotation
  10342. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10346. // ConnectorPhaseRotationMaxLength
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10351. // StopTransactionOnEVSideDisconnect
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10356. // StopTransactionOnInvalidId
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10361. // StopTxnAlignedData
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10366. // StopTxnAlignedDataMaxLength
  10367. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10371. // StopTxnSampledData
  10372. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10376. // StopTxnSampledDataMaxLength
  10377. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10380. {
  10381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10382. }
  10383. else
  10384. {
  10385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10386. }
  10387. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10389. // SupportedFeatureProfiles
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10394. // SupportedFeatureProfilesMaxLength
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10399. // TransactionMessageAttempts
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10403. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10405. // TransactionMessageRetryInterval
  10406. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10409. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10411. // UnlockConnectorOnEVSideDisconnect
  10412. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10416. // WebSocketPingInterval
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10421. //* Local Auth List Management Profile*/
  10422. #if 0
  10423. //For OCTT Test Case
  10424. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10427. #endif
  10428. #if 1
  10429. //LocalAuthListEnabled
  10430. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10434. #endif
  10435. //LocalAuthListMaxLength
  10436. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10440. //SendLocalListMaxLength
  10441. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "50");
  10445. //ReserveConnectorZeroSupported
  10446. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10450. //* Smart Charging Profile */
  10451. //ChargeProfileMaxStackLevel
  10452. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10456. // ChargingScheduleAllowedChargingRateUnit
  10457. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10461. // ChargingScheduleMaxPeriods
  10462. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10466. // ConnectorSwitch3to1PhaseSupported
  10467. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10470. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10471. // MaxChargingProfilesInstalled
  10472. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10476. fclose(outfile);
  10477. }
  10478. else
  10479. {
  10480. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10481. char keystr[60]={0};
  10482. char readonlystr[10]={0};
  10483. char valuestr[100]={0};
  10484. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10485. if(fp == NULL) {
  10486. DEBUG_INFO("Error opening file");
  10487. return FALSE;
  10488. }
  10489. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10490. {
  10491. //DEBUG_INFO("Get Configuration \n");
  10492. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10493. //*************************key*********************************/
  10494. loc = strstr(str, "key");
  10495. c = 0;
  10496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10497. while (loc[strlen("key")+3+c] != '\"')
  10498. {
  10499. sstr[c] = loc[strlen("key")+3+c];
  10500. c++;
  10501. }
  10502. sstr[c] = '\0';
  10503. strcpy(keystr,sstr);
  10504. //*************************readonly*********************************/
  10505. loc = strstr(str, "readonly");
  10506. c = 0;
  10507. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10508. while (loc[strlen("readonly")+2+c] != ',')
  10509. {
  10510. sstr[c] = loc[strlen("readonly")+2+c];
  10511. c++;
  10512. }
  10513. sstr[c] = '\0';
  10514. strcpy(readonlystr,sstr);
  10515. //*************************value*********************************/
  10516. loc = strstr(str, "value");
  10517. c = 0;
  10518. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10519. while (loc[strlen("value")+3+c] != '\"')
  10520. {
  10521. sstr[c] = loc[strlen("value")+3+c];
  10522. c++;
  10523. }
  10524. sstr[c] = '\0';
  10525. strcpy(valuestr,sstr);
  10526. // DEBUG_INFO("keystr=%s\n",keystr);
  10527. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10528. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10529. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10530. {
  10531. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10534. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10535. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10536. }
  10537. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10538. {
  10539. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10542. }
  10543. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10547. }
  10548. if(strcmp(keystr, "BlinkRepeat") == 0)
  10549. {
  10550. //Charger.BlinkRepeat = Integer.parseInt(value);
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10553. }
  10554. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10558. }
  10559. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10563. }
  10564. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10568. }
  10569. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10573. HeartBeatWaitTime = atoi(valuestr);
  10574. }
  10575. if(strcmp(keystr, "LightIntensity") == 0)
  10576. {
  10577. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10579. }
  10580. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10581. {
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10584. }
  10585. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10586. {
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10589. }
  10590. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10591. {
  10592. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10594. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10595. }
  10596. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10600. }
  10601. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10605. }
  10606. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10607. {
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10610. }
  10611. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10615. }
  10616. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10617. {
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10620. }
  10621. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10622. {
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10625. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10626. }
  10627. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10628. {
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10631. }
  10632. if(strcmp(keystr, "ResetRetries") == 0)
  10633. {
  10634. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10636. }
  10637. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10638. {
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10641. }
  10642. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10643. {
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10646. }
  10647. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10648. {
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10651. }
  10652. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10653. {
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10656. }
  10657. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10658. {
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10661. }
  10662. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10663. {
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10666. }
  10667. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10668. {
  10669. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10671. }
  10672. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10673. {
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10676. }
  10677. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10678. {
  10679. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10681. }
  10682. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10683. {
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10686. }
  10687. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10688. {
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10691. TransactionMessageAttemptsValue = atoi(valuestr);
  10692. }
  10693. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10694. {
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10697. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10698. }
  10699. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10700. {
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10703. }
  10704. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10705. {
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10708. }
  10709. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10710. {
  10711. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10713. }
  10714. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10715. {
  10716. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10718. }
  10719. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10720. {
  10721. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10723. }
  10724. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10725. {
  10726. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10728. }
  10729. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10730. {
  10731. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10733. }
  10734. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10735. {
  10736. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10738. }
  10739. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10740. {
  10741. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10743. }
  10744. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10745. {
  10746. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10748. }
  10749. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10750. {
  10751. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10753. }
  10754. }
  10755. fclose(fp);
  10756. }
  10757. return 0;
  10758. }
  10759. void StoreConfigurationTable(void)
  10760. {
  10761. FILE *outfile;
  10762. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10763. if(outfile == NULL)
  10764. {
  10765. DEBUG_INFO("Error opening file");
  10766. return ;
  10767. }
  10768. /*Core Profile*/
  10769. //AllowOfflineTxForUnknownId
  10770. /*
  10771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10772. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10775. */
  10776. //DEBUG_INFO("data=%s\n",data);
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10778. //AuthorizationCacheEnabled
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10785. //AuthorizeRemoteTxRequests
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10792. //BlinkRepeat
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10799. //ClockAlignedDataInterval
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10804. */
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10806. //ConnectionTimeOut
  10807. /*
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10811. */
  10812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10813. //GetConfigurationMaxKeys
  10814. /*
  10815. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10818. */
  10819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10820. // HeartbeatInterval
  10821. /*
  10822. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10825. */
  10826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10827. // LightIntensity
  10828. /*
  10829. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10832. */
  10833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10834. // LocalAuthorizeOffline
  10835. /*
  10836. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10839. */
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10841. // LocalPreAuthorize
  10842. /*
  10843. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10846. */
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10848. // MaxEnergyOnInvalidId
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10853. */
  10854. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10856. // MeterValuesAlignedData
  10857. /*
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10861. */
  10862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10863. // MeterValuesAlignedDataMaxLength
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10870. // MeterValuesSampledData
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10877. // MeterValuesSampledDataMaxLength
  10878. /*
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10882. */
  10883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10884. // MeterValueSampleInterval
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10891. // MinimumStatusDuration
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10896. */
  10897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10898. // NumberOfConnectors
  10899. /*
  10900. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10903. {
  10904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10905. }
  10906. else
  10907. {
  10908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10909. }
  10910. */
  10911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10912. // ResetRetries
  10913. /*
  10914. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10917. */
  10918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10919. // ConnectorPhaseRotation
  10920. /*
  10921. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10924. */
  10925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10926. // ConnectorPhaseRotationMaxLength
  10927. /*
  10928. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10931. */
  10932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10933. // StopTransactionOnEVSideDisconnect
  10934. /*
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10938. */
  10939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10940. // StopTransactionOnInvalidId
  10941. /*
  10942. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10945. */
  10946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10947. // StopTxnAlignedData
  10948. /*
  10949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10952. */
  10953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10954. // StopTxnAlignedDataMaxLength
  10955. /*
  10956. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10959. */
  10960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10961. // StopTxnSampledData
  10962. /*
  10963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10966. */
  10967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10968. // StopTxnSampledDataMaxLength
  10969. /*
  10970. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10973. */
  10974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10975. // SupportedFeatureProfiles
  10976. /*
  10977. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10980. */
  10981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10982. // SupportedFeatureProfilesMaxLength
  10983. /*
  10984. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10987. */
  10988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10989. // TransactionMessageAttempts
  10990. /*
  10991. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10994. */
  10995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10996. // TransactionMessageRetryInterval
  10997. /*
  10998. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11001. */
  11002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11003. // UnlockConnectorOnEVSideDisconnect
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11010. // WebSocketPingInterval
  11011. /*
  11012. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11015. */
  11016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11017. //* Local Auth List Management Profile*/
  11018. //LocalAuthListEnabled
  11019. /*
  11020. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11023. */
  11024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11025. //LocalAuthListMaxLength
  11026. /*
  11027. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11030. */
  11031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11032. //SendLocalListMaxLength
  11033. /*
  11034. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11037. */
  11038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11039. //ReserveConnectorZeroSupported
  11040. /*
  11041. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11044. */
  11045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11046. //* Smart Charging Profile */
  11047. //ChargeProfileMaxStackLevel
  11048. /*
  11049. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11052. */
  11053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11054. // ChargingScheduleAllowedChargingRateUnit
  11055. /*
  11056. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11059. */
  11060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11061. // ChargingScheduleMaxPeriods
  11062. /*
  11063. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11066. */
  11067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11068. // ConnectorSwitch3to1PhaseSupported
  11069. /*
  11070. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11073. */
  11074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11075. // MaxChargingProfilesInstalled
  11076. /*
  11077. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11080. */
  11081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11082. fclose(outfile);
  11083. }
  11084. void getKeyValue(char *keyReq)
  11085. {
  11086. int isEmpty = FALSE;
  11087. int isKnowKey = FALSE;
  11088. DEBUG_INFO("keyReq = %s\n", keyReq);
  11089. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11090. isEmpty = TRUE;
  11091. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11096. {
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11098. }
  11099. else
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11102. }
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11104. isKnowKey = TRUE;
  11105. }
  11106. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11111. {
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11113. }
  11114. else
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11117. }
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11119. isKnowKey = TRUE;
  11120. }
  11121. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11126. {
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11128. }
  11129. else
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11132. }
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11134. isKnowKey = TRUE;
  11135. }
  11136. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11141. {
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11143. }
  11144. else
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11147. }
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11149. isKnowKey = TRUE;
  11150. }
  11151. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11158. }
  11159. else
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11162. }
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11164. isKnowKey = TRUE;
  11165. }
  11166. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11171. {
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11173. }
  11174. else
  11175. {
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11177. }
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11179. isKnowKey = TRUE;
  11180. }
  11181. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11188. }
  11189. else
  11190. {
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11192. }
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11194. isKnowKey = TRUE;
  11195. }
  11196. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11203. }
  11204. else
  11205. {
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11207. }
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11209. isKnowKey = TRUE;
  11210. }
  11211. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11218. }
  11219. else
  11220. {
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11222. }
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11224. isKnowKey = TRUE;
  11225. }
  11226. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11233. }
  11234. else
  11235. {
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11237. }
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11239. isKnowKey = TRUE;
  11240. }
  11241. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11248. }
  11249. else
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11252. }
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11254. isKnowKey = TRUE;
  11255. }
  11256. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11263. }
  11264. else
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11267. }
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11269. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11270. isKnowKey = TRUE;
  11271. }
  11272. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11273. {
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11279. }
  11280. else
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11283. }
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11285. isKnowKey = TRUE;
  11286. }
  11287. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11292. {
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11294. }
  11295. else
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11298. }
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11300. isKnowKey = TRUE;
  11301. }
  11302. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11307. {
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11309. }
  11310. else
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11313. }
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11315. isKnowKey = TRUE;
  11316. }
  11317. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11324. }
  11325. else
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11328. }
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11330. isKnowKey = TRUE;
  11331. }
  11332. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11337. {
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11339. }
  11340. else
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11343. }
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11345. isKnowKey = TRUE;
  11346. }
  11347. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11352. {
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11354. }
  11355. else
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11358. }
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11360. isKnowKey = TRUE;
  11361. }
  11362. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11367. {
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11369. }
  11370. else
  11371. {
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11373. }
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11375. isKnowKey = TRUE;
  11376. }
  11377. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11384. }
  11385. else
  11386. {
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11388. }
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11390. isKnowKey = TRUE;
  11391. }
  11392. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11399. }
  11400. else
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11403. }
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11405. isKnowKey = TRUE;
  11406. }
  11407. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11414. }
  11415. else
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11418. }
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11420. isKnowKey = TRUE;
  11421. }
  11422. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11429. }
  11430. else
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11433. }
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11435. isKnowKey = TRUE;
  11436. }
  11437. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11444. }
  11445. else
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11448. }
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11450. isKnowKey = TRUE;
  11451. }
  11452. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11459. }
  11460. else
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11463. }
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11465. isKnowKey = TRUE;
  11466. }
  11467. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11474. }
  11475. else
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11478. }
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11480. isKnowKey = TRUE;
  11481. }
  11482. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11489. }
  11490. else
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11493. }
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11495. isKnowKey = TRUE;
  11496. }
  11497. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11504. }
  11505. else
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11508. }
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11510. isKnowKey = TRUE;
  11511. }
  11512. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11519. }
  11520. else
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11523. }
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11525. isKnowKey = TRUE;
  11526. }
  11527. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11534. }
  11535. else
  11536. {
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11538. }
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11540. isKnowKey = TRUE;
  11541. }
  11542. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11549. }
  11550. else
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11553. }
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11555. isKnowKey = TRUE;
  11556. }
  11557. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11564. }
  11565. else
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11568. }
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11570. isKnowKey = TRUE;
  11571. }
  11572. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11579. }
  11580. else
  11581. {
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11583. }
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11585. isKnowKey = TRUE;
  11586. }
  11587. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11592. {
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11594. }
  11595. else
  11596. {
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11598. }
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11600. isKnowKey = TRUE;
  11601. }
  11602. #if 1
  11603. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11607. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11610. }
  11611. else
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11614. }
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11616. isKnowKey = TRUE;
  11617. }
  11618. #endif
  11619. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11623. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11626. }
  11627. else
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11630. }
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11632. isKnowKey = TRUE;
  11633. }
  11634. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11638. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11641. }
  11642. else
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11645. }
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11647. isKnowKey = TRUE;
  11648. }
  11649. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11650. {
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11653. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11654. {
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11656. }
  11657. else
  11658. {
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11660. }
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11662. isKnowKey = TRUE;
  11663. }
  11664. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11665. {
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11668. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11669. {
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11671. }
  11672. else
  11673. {
  11674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11675. }
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11677. isKnowKey = TRUE;
  11678. }
  11679. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11680. {
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11683. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11686. }
  11687. else
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11690. }
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11692. isKnowKey = TRUE;
  11693. }
  11694. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11695. {
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11698. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11701. }
  11702. else
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11705. }
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11707. isKnowKey = TRUE;
  11708. }
  11709. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11710. {
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11713. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11716. }
  11717. else
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11720. }
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11722. isKnowKey = TRUE;
  11723. }
  11724. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11725. {
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11728. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11731. }
  11732. else
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11735. }
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11737. isKnowKey = TRUE;
  11738. }
  11739. //=========================================================
  11740. if(!isEmpty && !isKnowKey)
  11741. {
  11742. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11743. strcpy(unknownkey[UnknownKeynum], keyReq);
  11744. UnknownKeynum = UnknownKeynum + 1;
  11745. }
  11746. }
  11747. void processUnkownKey(void)
  11748. {
  11749. DEBUG_INFO("processUnkownKey...\n");
  11750. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11751. for(int index=0; index < UnknownKeynum; index++)
  11752. {
  11753. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11754. {
  11755. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11756. }
  11757. }
  11758. }
  11759. int setKeyValue(char *key, char *value)
  11760. {
  11761. int isSuccess = NotSupported;
  11762. int check_ascii=0;
  11763. char str[10]={0};
  11764. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11765. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11766. {
  11767. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11769. {
  11770. strcpy(str, (const char*)value);
  11771. for(int i = 0; str[i]; i++){
  11772. str[i] = tolower(str[i]);
  11773. }
  11774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11775. isSuccess = ConfigurationStatus_Accepted;
  11776. }
  11777. else
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. }
  11782. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11783. {
  11784. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11786. {
  11787. strcpy(str, (const char*)value);
  11788. for(int i = 0; str[i]; i++){
  11789. str[i] = tolower(str[i]);
  11790. }
  11791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11792. isSuccess = ConfigurationStatus_Accepted;
  11793. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11794. }
  11795. else
  11796. {
  11797. isSuccess = ConfigurationStatus_Rejected;
  11798. }
  11799. }
  11800. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11801. {
  11802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11803. {
  11804. strcpy(str, (const char*)value);
  11805. for(int i = 0; str[i]; i++)
  11806. {
  11807. str[i] = tolower(str[i]);
  11808. }
  11809. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11811. isSuccess = ConfigurationStatus_Accepted;
  11812. }
  11813. else
  11814. {
  11815. isSuccess = ConfigurationStatus_Rejected;
  11816. }
  11817. }
  11818. if(strcmp(key, "BlinkRepeat") == 0)
  11819. {
  11820. //Charger.BlinkRepeat = Integer.parseInt(value);
  11821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11822. {
  11823. check_ascii = value[0];
  11824. if( (check_ascii < 48) || (check_ascii > 57) )
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. else
  11829. {
  11830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11831. isSuccess = ConfigurationStatus_Accepted;
  11832. }
  11833. }
  11834. else
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. }
  11839. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11840. {
  11841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11842. {
  11843. check_ascii = value[0];
  11844. if( (check_ascii < 48) || (check_ascii > 57) )
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. else
  11849. {
  11850. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. }
  11854. }
  11855. else
  11856. {
  11857. isSuccess = ConfigurationStatus_Rejected;
  11858. }
  11859. }
  11860. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11861. {
  11862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11863. {
  11864. check_ascii = value[0];
  11865. if( (check_ascii < 48) || (check_ascii > 57) )
  11866. {
  11867. isSuccess = ConfigurationStatus_Rejected;
  11868. }
  11869. else
  11870. {
  11871. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11873. isSuccess = ConfigurationStatus_Accepted;
  11874. }
  11875. }
  11876. else
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. }
  11881. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11882. {
  11883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11884. {
  11885. check_ascii = value[0];
  11886. if( (check_ascii < 48) || (check_ascii > 57) )
  11887. {
  11888. isSuccess = ConfigurationStatus_Rejected;
  11889. }
  11890. else
  11891. {
  11892. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11894. isSuccess = ConfigurationStatus_Accepted;
  11895. }
  11896. }
  11897. else
  11898. {
  11899. isSuccess = ConfigurationStatus_Rejected;
  11900. }
  11901. }
  11902. if(strcmp(key, "HeartbeatInterval") == 0)
  11903. {
  11904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11905. {
  11906. check_ascii = value[0];
  11907. if( (check_ascii < 48) || (check_ascii > 57) )
  11908. {
  11909. isSuccess = ConfigurationStatus_Rejected;
  11910. }
  11911. else
  11912. {
  11913. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11915. HeartBeatWaitTime = atoi(value);
  11916. isSuccess = ConfigurationStatus_Accepted;
  11917. }
  11918. }
  11919. else
  11920. {
  11921. isSuccess = ConfigurationStatus_Rejected;
  11922. }
  11923. }
  11924. if(strcmp(key, "LightIntensity") == 0)
  11925. {
  11926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11927. {
  11928. check_ascii = value[0];
  11929. if( (check_ascii < 48) || (check_ascii > 57) )
  11930. {
  11931. isSuccess = ConfigurationStatus_Rejected;
  11932. }
  11933. else
  11934. {
  11935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11936. isSuccess = ConfigurationStatus_Accepted;
  11937. }
  11938. }
  11939. else
  11940. {
  11941. isSuccess = ConfigurationStatus_Rejected;
  11942. }
  11943. }
  11944. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11945. {
  11946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11947. {
  11948. strcpy(str, (const char*)value);
  11949. for(int i = 0; str[i]; i++)
  11950. {
  11951. str[i] = tolower(str[i]);
  11952. }
  11953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11954. isSuccess = ConfigurationStatus_Accepted;
  11955. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11956. }
  11957. else
  11958. {
  11959. isSuccess = ConfigurationStatus_Rejected;
  11960. }
  11961. }
  11962. if(strcmp(key, "LocalPreAuthorize") == 0)
  11963. {
  11964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11965. {
  11966. strcpy(str, (const char*)value);
  11967. for(int i = 0; str[i]; i++)
  11968. {
  11969. str[i] = tolower(str[i]);
  11970. }
  11971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11972. isSuccess = ConfigurationStatus_Accepted;
  11973. }
  11974. else
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. }
  11979. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11980. {
  11981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11982. {
  11983. check_ascii = value[0];
  11984. if( (check_ascii < 48) || (check_ascii > 57) )
  11985. {
  11986. isSuccess = ConfigurationStatus_Rejected;
  11987. }
  11988. else
  11989. {
  11990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11991. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11992. isSuccess = ConfigurationStatus_Accepted;
  11993. }
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12003. {
  12004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12005. isSuccess = ConfigurationStatus_Accepted;
  12006. }
  12007. else
  12008. {
  12009. isSuccess = ConfigurationStatus_Rejected;
  12010. }
  12011. }
  12012. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12013. {
  12014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12015. {
  12016. check_ascii = value[0];
  12017. if( (check_ascii < 48) || (check_ascii > 57) )
  12018. {
  12019. isSuccess = ConfigurationStatus_Rejected;
  12020. }
  12021. else
  12022. {
  12023. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12025. isSuccess = ConfigurationStatus_Accepted;
  12026. }
  12027. }
  12028. else
  12029. {
  12030. isSuccess = ConfigurationStatus_Rejected;
  12031. }
  12032. }
  12033. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12034. {
  12035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12036. {
  12037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12038. isSuccess = ConfigurationStatus_Accepted;
  12039. }
  12040. else
  12041. {
  12042. isSuccess = ConfigurationStatus_Rejected;
  12043. }
  12044. }
  12045. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12046. {
  12047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12048. {
  12049. check_ascii = value[0];
  12050. if( (check_ascii < 48) || (check_ascii > 57) )
  12051. {
  12052. isSuccess = ConfigurationStatus_Rejected;
  12053. }
  12054. else
  12055. {
  12056. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12058. isSuccess = ConfigurationStatus_Accepted;
  12059. }
  12060. }
  12061. else
  12062. {
  12063. isSuccess = ConfigurationStatus_Rejected;
  12064. }
  12065. }
  12066. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12067. {
  12068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12069. {
  12070. check_ascii = value[0];
  12071. if( (check_ascii < 48) || (check_ascii > 57) )
  12072. {
  12073. isSuccess = ConfigurationStatus_Rejected;
  12074. }
  12075. else
  12076. {
  12077. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12079. isSuccess = ConfigurationStatus_Accepted;
  12080. }
  12081. }
  12082. else
  12083. {
  12084. isSuccess = ConfigurationStatus_Rejected;
  12085. }
  12086. }
  12087. if(strcmp(key, "MinimumStatusDuration") == 0)
  12088. {
  12089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12090. {
  12091. check_ascii = value[0];
  12092. if( (check_ascii < 48) || (check_ascii > 57) )
  12093. {
  12094. isSuccess = ConfigurationStatus_Rejected;
  12095. }
  12096. else
  12097. {
  12098. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. else
  12103. {
  12104. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12106. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12107. isSuccess = ConfigurationStatus_Accepted;
  12108. }
  12109. }
  12110. }
  12111. else
  12112. {
  12113. isSuccess = ConfigurationStatus_Rejected;
  12114. }
  12115. }
  12116. if(strcmp(key, "NumberOfConnectors") == 0)
  12117. {
  12118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12119. {
  12120. check_ascii = value[0];
  12121. if( (check_ascii < 48) || (check_ascii > 57) )
  12122. {
  12123. isSuccess = ConfigurationStatus_Rejected;
  12124. }
  12125. else
  12126. {
  12127. //Charger.ResetRetries = Integer.parseInt(value);
  12128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12129. isSuccess = ConfigurationStatus_Accepted;
  12130. }
  12131. }
  12132. else
  12133. {
  12134. isSuccess = ConfigurationStatus_Rejected;
  12135. }
  12136. }
  12137. if(strcmp(key, "ResetRetries") == 0)
  12138. {
  12139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12140. {
  12141. check_ascii = value[0];
  12142. if( (check_ascii < 48) || (check_ascii > 57) )
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. else
  12147. {
  12148. //Charger.ResetRetries = Integer.parseInt(value);
  12149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12150. isSuccess = ConfigurationStatus_Accepted;
  12151. }
  12152. }
  12153. else
  12154. {
  12155. isSuccess = ConfigurationStatus_Rejected;
  12156. }
  12157. }
  12158. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12159. {
  12160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12161. {
  12162. strcpy(str, (const char*)value);
  12163. for(int i = 0; str[i]; i++)
  12164. {
  12165. str[i] = tolower(str[i]);
  12166. }
  12167. if(strcmp(str, "notapplicable")== 0)
  12168. {
  12169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12170. isSuccess = ConfigurationStatus_Accepted;
  12171. }
  12172. else if(strcmp(str, "unknown")== 0)
  12173. {
  12174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12175. isSuccess = ConfigurationStatus_Accepted;
  12176. }
  12177. else if(strcmp(str, "rst")== 0)
  12178. {
  12179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12180. isSuccess = ConfigurationStatus_Accepted;
  12181. }
  12182. else if(strcmp(str, "rts")== 0)
  12183. {
  12184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12185. isSuccess = ConfigurationStatus_Accepted;
  12186. }
  12187. else if(strcmp(str, "srt")== 0)
  12188. {
  12189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12190. isSuccess = ConfigurationStatus_Accepted;
  12191. }
  12192. else if(strcmp(str, "str")== 0)
  12193. {
  12194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12195. isSuccess = ConfigurationStatus_Accepted;
  12196. }
  12197. else if(strcmp(str, "trs")== 0)
  12198. {
  12199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12200. isSuccess = ConfigurationStatus_Accepted;
  12201. }
  12202. else if(strcmp(str, "tsr")== 0)
  12203. {
  12204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12205. isSuccess = ConfigurationStatus_Accepted;
  12206. }
  12207. else
  12208. {
  12209. isSuccess = ConfigurationStatus_Rejected;
  12210. }
  12211. }
  12212. else
  12213. {
  12214. isSuccess = ConfigurationStatus_Rejected;
  12215. }
  12216. }
  12217. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12218. {
  12219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12220. {
  12221. check_ascii = value[0];
  12222. if( (check_ascii < 48) || (check_ascii > 57) )
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. else
  12227. {
  12228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12229. isSuccess = ConfigurationStatus_Accepted;
  12230. }
  12231. }
  12232. else
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. }
  12237. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12238. {
  12239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12240. {
  12241. strcpy(str, (const char*)value);
  12242. for(int i = 0; str[i]; i++)
  12243. {
  12244. str[i] = tolower(str[i]);
  12245. }
  12246. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12248. isSuccess = ConfigurationStatus_Accepted;
  12249. }
  12250. else
  12251. {
  12252. isSuccess = ConfigurationStatus_Rejected;
  12253. }
  12254. }
  12255. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12256. {
  12257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12258. {
  12259. strcpy(str, (const char*)value);
  12260. for(int i = 0; str[i]; i++)
  12261. {
  12262. str[i] = tolower(str[i]);
  12263. }
  12264. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12266. isSuccess = ConfigurationStatus_Accepted;
  12267. }
  12268. else
  12269. {
  12270. isSuccess = ConfigurationStatus_Rejected;
  12271. }
  12272. }
  12273. if(strcmp(key, "StopTxnAlignedData") == 0)
  12274. {
  12275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12276. {
  12277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12278. isSuccess = ConfigurationStatus_Accepted;
  12279. }
  12280. else
  12281. {
  12282. isSuccess = ConfigurationStatus_Rejected;
  12283. }
  12284. }
  12285. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12286. {
  12287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12288. {
  12289. check_ascii = value[0];
  12290. if( (check_ascii < 48) || (check_ascii > 57) )
  12291. {
  12292. isSuccess = ConfigurationStatus_Rejected;
  12293. }
  12294. else
  12295. {
  12296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12297. isSuccess = ConfigurationStatus_Accepted;
  12298. }
  12299. }
  12300. else
  12301. {
  12302. isSuccess = ConfigurationStatus_Rejected;
  12303. }
  12304. }
  12305. if(strcmp(key, "StopTxnSampledData") == 0)
  12306. {
  12307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12308. {
  12309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12310. isSuccess = ConfigurationStatus_Accepted;
  12311. }
  12312. else
  12313. {
  12314. isSuccess = ConfigurationStatus_Rejected;
  12315. }
  12316. }
  12317. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12318. {
  12319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12320. {
  12321. check_ascii = value[0];
  12322. if( (check_ascii < 48) || (check_ascii > 57) )
  12323. {
  12324. isSuccess = ConfigurationStatus_Rejected;
  12325. }
  12326. else
  12327. {
  12328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12329. isSuccess = ConfigurationStatus_Accepted;
  12330. }
  12331. }
  12332. else
  12333. {
  12334. isSuccess = ConfigurationStatus_Rejected;
  12335. }
  12336. }
  12337. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12338. {
  12339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12340. {
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12342. isSuccess = ConfigurationStatus_Accepted;
  12343. }
  12344. else
  12345. {
  12346. isSuccess = ConfigurationStatus_Rejected;
  12347. }
  12348. }
  12349. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12350. {
  12351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12352. {
  12353. check_ascii = value[0];
  12354. if( (check_ascii < 48) || (check_ascii > 57) )
  12355. {
  12356. isSuccess = ConfigurationStatus_Rejected;
  12357. }
  12358. else
  12359. {
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12361. isSuccess = ConfigurationStatus_Accepted;
  12362. }
  12363. }
  12364. else
  12365. {
  12366. isSuccess = ConfigurationStatus_Rejected;
  12367. }
  12368. }
  12369. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12370. {
  12371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12372. {
  12373. check_ascii = value[0];
  12374. if( (check_ascii < 48) || (check_ascii > 57) )
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. else
  12379. {
  12380. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12382. TransactionMessageAttemptsValue = atoi(value);
  12383. isSuccess = ConfigurationStatus_Accepted;
  12384. }
  12385. }
  12386. else
  12387. {
  12388. isSuccess = ConfigurationStatus_Rejected;
  12389. }
  12390. }
  12391. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12392. {
  12393. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12394. {
  12395. check_ascii = value[0];
  12396. if( (check_ascii < 48) || (check_ascii > 57) )
  12397. {
  12398. isSuccess = ConfigurationStatus_Rejected;
  12399. }
  12400. else
  12401. {
  12402. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12404. TransactionMessageRetryIntervalValue = atoi(value);
  12405. isSuccess = ConfigurationStatus_Accepted;
  12406. }
  12407. }
  12408. else
  12409. {
  12410. isSuccess = ConfigurationStatus_Rejected;
  12411. }
  12412. }
  12413. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12414. {
  12415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12416. {
  12417. strcpy(str, (const char*)value);
  12418. for(int i = 0; str[i]; i++)
  12419. {
  12420. str[i] = tolower(str[i]);
  12421. }
  12422. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12424. isSuccess = ConfigurationStatus_Accepted;
  12425. }
  12426. else
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. }
  12431. if(strcmp(key, "WebSocketPingInterval") == 0)
  12432. {
  12433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12434. {
  12435. check_ascii = value[0];
  12436. if( (check_ascii < 48) || (check_ascii > 57) )
  12437. {
  12438. isSuccess = ConfigurationStatus_Rejected;
  12439. }
  12440. else
  12441. {
  12442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12443. isSuccess = ConfigurationStatus_Accepted;
  12444. }
  12445. }
  12446. else
  12447. {
  12448. isSuccess = ConfigurationStatus_Rejected;
  12449. }
  12450. }
  12451. #if 0
  12452. //For OCPP Test Case
  12453. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12454. {
  12455. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12456. {
  12457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12458. isSuccess = ConfigurationStatus_Accepted;
  12459. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12460. }
  12461. else
  12462. {
  12463. isSuccess = ConfigurationStatus_Rejected;
  12464. }
  12465. }
  12466. #endif
  12467. #if 1
  12468. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12469. {
  12470. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12471. {
  12472. strcpy(str, (const char*)value);
  12473. for(int i = 0; str[i]; i++)
  12474. {
  12475. str[i] = tolower(str[i]);
  12476. }
  12477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12478. isSuccess = ConfigurationStatus_Accepted;
  12479. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12480. }
  12481. else
  12482. {
  12483. isSuccess = ConfigurationStatus_Rejected;
  12484. }
  12485. }
  12486. #endif
  12487. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12488. {
  12489. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12490. {
  12491. check_ascii = value[0];
  12492. if( (check_ascii < 48) || (check_ascii > 57) )
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. else
  12497. {
  12498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12499. isSuccess = ConfigurationStatus_Accepted;
  12500. }
  12501. }
  12502. else
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. }
  12507. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12508. {
  12509. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12510. {
  12511. check_ascii = value[0];
  12512. if( (check_ascii < 48) || (check_ascii > 57) )
  12513. {
  12514. isSuccess = ConfigurationStatus_Rejected;
  12515. }
  12516. else
  12517. {
  12518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12519. isSuccess = ConfigurationStatus_Accepted;
  12520. }
  12521. }
  12522. else
  12523. {
  12524. isSuccess = ConfigurationStatus_Rejected;
  12525. }
  12526. }
  12527. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12528. {
  12529. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12530. {
  12531. strcpy(str, (const char*)value);
  12532. for(int i = 0; str[i]; i++)
  12533. {
  12534. str[i] = tolower(str[i]);
  12535. }
  12536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12537. isSuccess = ConfigurationStatus_Accepted;
  12538. }
  12539. else
  12540. {
  12541. isSuccess = ConfigurationStatus_Rejected;
  12542. }
  12543. }
  12544. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12545. {
  12546. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12547. {
  12548. check_ascii = value[0];
  12549. if( (check_ascii < 48) || (check_ascii > 57) )
  12550. {
  12551. isSuccess = ConfigurationStatus_Rejected;
  12552. }
  12553. else
  12554. {
  12555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12556. isSuccess = ConfigurationStatus_Accepted;
  12557. }
  12558. }
  12559. else
  12560. {
  12561. isSuccess = ConfigurationStatus_Rejected;
  12562. }
  12563. }
  12564. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12565. {
  12566. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12567. {
  12568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12569. isSuccess = ConfigurationStatus_Accepted;
  12570. }
  12571. else
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. }
  12576. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12577. {
  12578. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12579. {
  12580. check_ascii = value[0];
  12581. if( (check_ascii < 48) || (check_ascii > 57) )
  12582. {
  12583. isSuccess = ConfigurationStatus_Rejected;
  12584. }
  12585. else
  12586. {
  12587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12588. isSuccess = ConfigurationStatus_Accepted;
  12589. }
  12590. }
  12591. else
  12592. {
  12593. isSuccess = ConfigurationStatus_Rejected;
  12594. }
  12595. }
  12596. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12597. {
  12598. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12599. {
  12600. strcpy(str, (const char*)value);
  12601. for(int i = 0; str[i]; i++)
  12602. {
  12603. str[i] = tolower(str[i]);
  12604. }
  12605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12606. isSuccess = ConfigurationStatus_Accepted;
  12607. }
  12608. else
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. }
  12613. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12614. {
  12615. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12616. {
  12617. check_ascii = value[0];
  12618. if( (check_ascii < 48) || (check_ascii > 57) )
  12619. {
  12620. isSuccess = ConfigurationStatus_Rejected;
  12621. }
  12622. else
  12623. {
  12624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12625. isSuccess = ConfigurationStatus_Accepted;
  12626. }
  12627. }
  12628. else
  12629. {
  12630. isSuccess = ConfigurationStatus_Rejected;
  12631. }
  12632. }
  12633. return isSuccess;
  12634. }
  12635. int TransactionMessageAttemptsGet(void)
  12636. {
  12637. return TransactionMessageAttemptsValue;
  12638. }
  12639. int FirstHeartBeatResponse(void)
  12640. {
  12641. return FirstHeartBeat;
  12642. }
  12643. int TransactionMessageRetryIntervalGet(void)
  12644. {
  12645. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12646. }
  12647. int ReadHttpStatus(int sock)
  12648. {
  12649. //char c;
  12650. char buff[1024]="",*ptr=buff+1;
  12651. int bytes_received, status;
  12652. DEBUG_INFO("Begin Response ..\n");
  12653. while((bytes_received = recv(sock, ptr, 1, 0))){
  12654. if(bytes_received==-1){
  12655. perror("ReadHttpStatus");
  12656. exit(1);
  12657. }
  12658. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12659. ptr++;
  12660. }
  12661. *ptr=0;
  12662. ptr=buff+1;
  12663. sscanf(ptr,"%*s %d ", &status);
  12664. DEBUG_INFO("%s\n",ptr);
  12665. DEBUG_INFO("status=%d\n",status);
  12666. DEBUG_INFO("End Response ..\n");
  12667. return (bytes_received>0)?status:0;
  12668. }
  12669. //the only filed that it parsed is 'Content-Length'
  12670. int ParseHeader(int sock)
  12671. {
  12672. //char c;
  12673. char buff[1024]="",*ptr=buff+4;
  12674. int bytes_received;
  12675. DEBUG_INFO("Begin HEADER ..\n");
  12676. while((bytes_received = recv(sock, ptr, 1, 0))){
  12677. if(bytes_received==-1){
  12678. perror("Parse Header");
  12679. exit(1);
  12680. }
  12681. if(
  12682. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12683. (ptr[-1]=='\r') && (*ptr=='\n' )
  12684. ) break;
  12685. ptr++;
  12686. }
  12687. *ptr=0;
  12688. ptr=buff+4;
  12689. //printf("%s",ptr);
  12690. if(bytes_received){
  12691. ptr=strstr(ptr,"Content-Length:");
  12692. if(ptr){
  12693. sscanf(ptr,"%*s %d",&bytes_received);
  12694. }else
  12695. bytes_received=-1; //unknown size
  12696. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12697. }
  12698. DEBUG_INFO("End HEADER ..\n");
  12699. return bytes_received ;
  12700. }
  12701. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12702. {
  12703. char rmFileCmd[100]={0};
  12704. char FilePath[100]={0};
  12705. char ftpbuf[200];
  12706. int systemresult;
  12707. //DEBUG_INFO("filename=%s\n",filename);
  12708. //DEBUG_INFO("url=%s\n",url);
  12709. sprintf(FilePath,"/mnt/%s",filename);
  12710. if((access(FilePath,F_OK))!=-1)
  12711. {
  12712. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12713. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12714. system(rmFileCmd);
  12715. }
  12716. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12717. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12718. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12719. systemresult = system(ftpbuf);
  12720. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12721. if(systemresult != 0)
  12722. {
  12723. DEBUG_INFO("http DownLoad error!\n");
  12724. return FALSE;
  12725. }
  12726. return TRUE;
  12727. }
  12728. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12729. {
  12730. char rmFileCmd[100]={0};
  12731. char FilePath[100]={0};
  12732. char ftpbuf[200];
  12733. int systemresult;
  12734. //char temp[100];
  12735. sprintf(FilePath,"/mnt/%s",filename);
  12736. if((access(FilePath,F_OK))!=-1)
  12737. {
  12738. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12739. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12740. system(rmFileCmd);
  12741. }
  12742. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12743. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12744. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12745. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12746. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12747. systemresult = system(ftpbuf);
  12748. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12749. if(systemresult != 0)
  12750. {
  12751. printf("wget error!\n");
  12752. return FALSE;
  12753. }
  12754. return TRUE;
  12755. }
  12756. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12757. {
  12758. char rmFileCmd[100]={0};
  12759. char FilePath[100]={0};
  12760. char ftpbuf[200];
  12761. int systemresult;
  12762. //DEBUG_INFO("filename=%s\n",filename);
  12763. //DEBUG_INFO("url=%s\n",url);
  12764. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12765. if((access(FilePath,F_OK))!=-1)
  12766. {
  12767. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12768. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12769. system(rmFileCmd);
  12770. }
  12771. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12772. if(fp == NULL)
  12773. {
  12774. DEBUG_INFO("log is NULL\n");
  12775. return FALSE;
  12776. }
  12777. else
  12778. {
  12779. fprintf(fp, "%s\n", url);
  12780. fprintf(fp, "%s\n", filename);
  12781. fclose(fp);
  12782. }
  12783. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12784. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12785. systemresult = system(ftpbuf);
  12786. DEBUG_INFO("systemresult = %d\n",systemresult);
  12787. if(systemresult != 0)
  12788. {
  12789. DEBUG_INFO("http upload error!\n");
  12790. return FALSE;
  12791. }
  12792. return TRUE;
  12793. }
  12794. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12795. {
  12796. struct hostent* server;
  12797. char *IPbuffer;
  12798. char ftpbuf[200];
  12799. int systemresult;
  12800. // To retrieve host information
  12801. server = gethostbyname(location);
  12802. // To convert an Internet network
  12803. // address into ASCII string
  12804. IPbuffer = inet_ntoa(*((struct in_addr*)
  12805. server->h_addr_list[0]));
  12806. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12807. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12808. /* format : ftpput -u username -p passwd IP target source*/
  12809. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12810. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12811. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12812. systemresult = system(ftpbuf);
  12813. DEBUG_INFO("systemresult=%d\n",systemresult);
  12814. if(systemresult != 0)
  12815. {
  12816. DEBUG_INFO("ftpput error!\n");
  12817. return FALSE;
  12818. }
  12819. return TRUE;
  12820. }
  12821. /**
  12822. * Place the contents of the specified file into a memory buffer
  12823. *
  12824. * @param[in] filename The path and name of the file to read
  12825. * @param[out] filebuffer A pointer to the contents in memory
  12826. * @return status 0 success, 1 on failure
  12827. */
  12828. int get_file_contents(const char* filename, char** outbuffer) {
  12829. FILE* file = NULL;
  12830. long filesize;
  12831. const int blocksize = 1;
  12832. size_t readsize;
  12833. char* filebuffer;
  12834. // Open the file
  12835. file = fopen(filename, "r");
  12836. if (NULL == file)
  12837. {
  12838. printf("'%s' not opened\n", filename);
  12839. exit(EXIT_FAILURE);
  12840. }
  12841. // Determine the file size
  12842. fseek(file, 0, SEEK_END);
  12843. filesize = ftell(file);
  12844. rewind (file);
  12845. // Allocate memory for the file contents
  12846. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12847. *outbuffer = filebuffer;
  12848. if (filebuffer == NULL)
  12849. {
  12850. fputs ("malloc out-of-memory", stderr);
  12851. exit(EXIT_FAILURE);
  12852. }
  12853. // Read in the file
  12854. readsize = fread(filebuffer, blocksize, filesize, file);
  12855. if (readsize != filesize)
  12856. {
  12857. fputs ("didn't read file completely",stderr);
  12858. exit(EXIT_FAILURE);
  12859. }
  12860. // Clean exit
  12861. fclose(file);
  12862. return EXIT_SUCCESS;
  12863. }
  12864. static int selectSqlCount = 0;
  12865. static int callback(void *data, int argc, char **argv, char **azColName){
  12866. int i;
  12867. //printf("%s: ", (const char*)data);
  12868. selectSqlCount = argc;
  12869. for(i = 0; i<argc; i++){
  12870. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12871. }
  12872. //printf("\n");
  12873. return 0;
  12874. }
  12875. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12876. //int i;
  12877. //printf("%s:\n", (const char*)data);
  12878. localversion = argv[5] ? atoi(argv[5]) : 0;
  12879. //printf("localversion=%d\n", localversion);
  12880. return 0;
  12881. }
  12882. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12883. //int i;
  12884. //printf("%s:\n", (const char*)data);
  12885. //idTag
  12886. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12887. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12888. //parentIdTag
  12889. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12890. //expir_date
  12891. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12892. //status
  12893. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12894. //version
  12895. idTagQuery.listVersionInt = atoi(argv[5]);
  12896. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12897. return 0;
  12898. }
  12899. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12900. {
  12901. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12902. // printf("localversion=%d\n", localversion);
  12903. return 0;
  12904. }
  12905. //=========================================
  12906. // Sqlite3 related function
  12907. //=========================================
  12908. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12909. {
  12910. for (int i = 0; i < n_columns; i++)
  12911. {
  12912. DEBUG_INFO("%s/t", col_values[i]);
  12913. }
  12914. DEBUG_INFO("/n");
  12915. return 0;
  12916. }
  12917. void OCPP_getListVerion()
  12918. {
  12919. int rc = 0;
  12920. // const char* data = "Callback function called";
  12921. char sql[100];
  12922. char zErrMsg[100];
  12923. memset(sql, 0, 100);
  12924. memset(zErrMsg, 0, 100);
  12925. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12926. /* Execute SQL statement */
  12927. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12928. if( rc != SQLITE_OK )
  12929. {
  12930. DEBUG_INFO("SQL error: %s", zErrMsg);
  12931. }
  12932. }
  12933. void OCPP_getIdTag(char idTag[])
  12934. {
  12935. int rc = 0;
  12936. // const char* data = "Callback function called";
  12937. char sql[100];
  12938. char zErrMsg[100];
  12939. memset(sql, 0, 100);
  12940. memset(zErrMsg, 0, 100);
  12941. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12942. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12943. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12944. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12945. /* Execute SQL statement */
  12946. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12947. if( rc != SQLITE_OK )
  12948. {
  12949. DEBUG_INFO("SQL error: %s", zErrMsg);
  12950. }
  12951. //return ver;
  12952. }
  12953. void OCPP_get_TableAuthlocalAllData(void)
  12954. {
  12955. int rc = 0;
  12956. char sql[100];
  12957. char zErrMsg[100];
  12958. memset(sql, 0, 100);
  12959. memset(zErrMsg, 0, 100);
  12960. sprintf(sql,"select * from ocpp_auth_local ");
  12961. /* Execute SQL statement */
  12962. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12963. if( rc != SQLITE_OK )
  12964. {
  12965. DEBUG_INFO("SQL error: %s", zErrMsg);
  12966. }
  12967. //return ver;
  12968. }
  12969. int OCPP_cleanLocalList()
  12970. {
  12971. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12972. char *errMsg = 0;
  12973. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12974. if (SQLITE_OK != rc)
  12975. {
  12976. DEBUG_INFO("%s\n",errMsg);
  12977. return FALSE;
  12978. }
  12979. return TRUE;
  12980. }
  12981. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12982. {
  12983. int isSuccess = FALSE;
  12984. int ret = 0;
  12985. //const char* data = "Callback function called";
  12986. char sql[300];
  12987. char zErrMsg[200];
  12988. memset(sql, 0, 300);
  12989. memset(zErrMsg, 0, 200);
  12990. 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);
  12991. //* Execute SQL statement */
  12992. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12993. if( ret != SQLITE_OK )
  12994. {
  12995. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12996. return isSuccess;
  12997. }
  12998. memset(sql, 0, 300);
  12999. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13000. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13001. if( ret != SQLITE_OK )
  13002. {
  13003. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13004. return isSuccess;
  13005. }
  13006. isSuccess = TRUE;
  13007. return isSuccess;
  13008. }
  13009. void OCPP_deleteIdTag(char idTag[])
  13010. {
  13011. //int ver = 0;
  13012. //int isSuccess = FALSE;
  13013. int rc = 0;
  13014. char sql[100];
  13015. char zErrMsg[100];
  13016. memset(sql, 0, 100);
  13017. memset(zErrMsg, 0, 100);
  13018. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13019. //* Execute SQL statement */
  13020. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13021. if( rc != SQLITE_OK )
  13022. {
  13023. DEBUG_INFO("SQL error: %s", zErrMsg);
  13024. }
  13025. }
  13026. int GetOcppServerURL()
  13027. {
  13028. int result = FALSE;
  13029. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13030. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13031. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13032. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13033. {
  13034. #if 1
  13035. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13036. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13037. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13038. #endif
  13039. result = TRUE;
  13040. goto End;
  13041. }
  13042. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13043. {
  13044. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13045. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13046. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13047. result = TRUE;
  13048. goto End;
  13049. }
  13050. else
  13051. {
  13052. strcpy(OcppHost,"");
  13053. }
  13054. End:
  13055. return result;
  13056. }
  13057. int GetOcppPath()
  13058. {
  13059. int result = FALSE;
  13060. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13061. {
  13062. if(OcppTempPath == NULL)
  13063. {
  13064. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13065. }
  13066. else
  13067. {
  13068. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13069. }
  13070. result = TRUE;
  13071. goto End;
  13072. }
  13073. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13074. {
  13075. if(OcppTempPath == NULL)
  13076. {
  13077. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13078. }
  13079. else
  13080. {
  13081. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13082. }
  13083. result = TRUE;
  13084. goto End;
  13085. }
  13086. else
  13087. {
  13088. strcpy(OcppPath,"");
  13089. }
  13090. End:
  13091. return result;
  13092. }
  13093. int GetOcppPort()
  13094. {
  13095. return OcppPort;
  13096. }
  13097. int GetOcppConnStatus(void)
  13098. {
  13099. return ShmOCPP16Data->OcppConnStatus;
  13100. }
  13101. void SetOcppConnStatus(uint8_t status)
  13102. {
  13103. ShmOCPP16Data->OcppConnStatus = status;
  13104. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13105. }
  13106. int GetHeartBeatWithNOResponse(void)
  13107. {
  13108. return HeartBeatWithNOResponse;
  13109. }
  13110. void SetHeartBeatWithNOResponse(void)
  13111. {
  13112. HeartBeatWithNOResponse = 0;
  13113. }
  13114. void GetStartTransactionIdTag(int gun_index)
  13115. {
  13116. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13117. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13118. }
  13119. int GetTransactionId(int gunindex, unsigned char idTag[])
  13120. {
  13121. char ch;
  13122. FILE *fptr1;
  13123. int temptransactionId;
  13124. char str[100]={0};
  13125. temptransactionId = 0;
  13126. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13127. {
  13128. DEBUG_INFO("IdTag is empty.\n");
  13129. return temptransactionId;
  13130. }
  13131. /*------ Read the file ----------------*/
  13132. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13133. if (!fptr1)
  13134. {
  13135. DEBUG_INFO("QueueTransactionId file open error.\n");
  13136. //printf(" File not found or unable to open the input file!!\n");
  13137. return temptransactionId;
  13138. }
  13139. ch=fgetc(fptr1);
  13140. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13141. rewind(fptr1);
  13142. if(ch!=EOF)
  13143. {
  13144. // printf("%c",ch);
  13145. while (fgets(str, 100, fptr1) != NULL)
  13146. {
  13147. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13148. if(str[0]=='\0')
  13149. {
  13150. break;
  13151. }
  13152. char *revbuf[8] = {0}; //存放分割後的子字串
  13153. int num = 0;//分割後子字串的個數
  13154. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13155. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13156. {
  13157. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13158. {
  13159. temptransactionId = atoi(revbuf[2]);
  13160. break;
  13161. }
  13162. }
  13163. }
  13164. }
  13165. fclose(fptr1);
  13166. /*------- End of reading ---------------*/
  13167. return temptransactionId;
  13168. }
  13169. void SetTransactionIdZero(int transactionId)
  13170. {
  13171. char ch;
  13172. FILE *fptr1, *fptr2;
  13173. int temptransactionId = 0;
  13174. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13175. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13176. if (!fptr1)
  13177. {
  13178. //printf(" File not found or unable to open the input file!!\n");
  13179. return ;
  13180. }
  13181. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13182. if (!fptr2)
  13183. {
  13184. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13185. fclose(fptr1);
  13186. return ;
  13187. }
  13188. ch=fgetc(fptr1);
  13189. rewind(fptr1);
  13190. if(ch!=EOF)
  13191. {
  13192. // copy all contents to the temporary file except the specific line
  13193. while (fgets(str, 100, fptr1) != NULL)
  13194. {
  13195. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13196. if(str[0]=='\0')
  13197. {
  13198. break;
  13199. }
  13200. char *revbuf[8] = {0};
  13201. int num = 0;
  13202. strcpy(strtemp, str);
  13203. splitstring(str,",",revbuf,&num);
  13204. if(revbuf[2][0] != '\0')
  13205. {
  13206. temptransactionId = atoi(revbuf[2]);
  13207. if(transactionId != temptransactionId)
  13208. {
  13209. fprintf(fptr2, "%s\n", strtemp);
  13210. }
  13211. }
  13212. }
  13213. }
  13214. fclose(fptr1);
  13215. fclose(fptr2);
  13216. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13217. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13218. /*------ Read the file ----------------*/
  13219. }
  13220. int InternetDisconnect(void)
  13221. {
  13222. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13223. }
  13224. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13225. void storeTempStopTransaction(int gun_index)
  13226. {
  13227. char guid[37]={0};
  13228. int tempIndex = 0;
  13229. DEBUG_INFO("storeTempStopTransaction...\n");
  13230. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13231. //ENERGY_ACTIVE_IMPORT_REGISTER
  13232. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13233. if(gunType[gun_index] == 'J')
  13234. {
  13235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13236. {
  13237. tempIndex = ((gun_index==2) ? 1: 0);
  13238. }
  13239. else
  13240. {
  13241. tempIndex = gun_index;
  13242. }
  13243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13244. {
  13245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13246. {
  13247. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13248. }
  13249. }// END OF CHAdeMO_QUANTITY
  13250. }
  13251. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13252. {
  13253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13254. {
  13255. tempIndex = ((gun_index==2) ? 1: 0);
  13256. }
  13257. else
  13258. {
  13259. tempIndex = gun_index;
  13260. }
  13261. for (int index = 0; index < CCS_QUANTITY; index++)
  13262. {
  13263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13264. {
  13265. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13266. }
  13267. }// END OF CCS_QUANTITY
  13268. }
  13269. else if(gunType[gun_index] == 'G')
  13270. {
  13271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13272. {
  13273. tempIndex = ((gun_index==2) ? 1: 0);
  13274. }
  13275. else
  13276. {
  13277. tempIndex = gun_index;
  13278. }
  13279. for (int index = 0; index < GB_QUANTITY; index++)
  13280. {
  13281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13282. {
  13283. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13284. }
  13285. }// END OF GB_QUANTITY
  13286. }
  13287. else
  13288. {
  13289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13290. {
  13291. tempIndex = 2;
  13292. }
  13293. else
  13294. {
  13295. tempIndex = gun_index;
  13296. }
  13297. for (int index = 0; index < AC_QUANTITY; index++)
  13298. {
  13299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13300. {
  13301. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13302. }
  13303. }// END OF AC_QUANTITY
  13304. }
  13305. //Stop Transaction Time
  13306. struct timeval tmnow;
  13307. struct tm *tm;
  13308. char buf[28];//, usec_buf[6];
  13309. gettimeofday(&tmnow, NULL);
  13310. time_t t;
  13311. t = time(NULL);
  13312. /*UTC time and date*/
  13313. tm = gmtime(&t);
  13314. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13316. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13318. random_uuid(guid);
  13319. /***********************************transactionData******************************************************/
  13320. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13322. //=================================
  13323. //1. Transaction_Begin
  13324. //=================================
  13325. // Energy.Active.Export.Interval
  13326. //idx_sample=0;
  13327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13330. 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*/]);
  13331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13332. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13333. {
  13334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13335. }
  13336. else
  13337. {
  13338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13339. }
  13340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13342. //=================================
  13343. //2. Transaction_End
  13344. //=================================
  13345. //2.1 Current.Export
  13346. //idx_sample=1;
  13347. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13348. if(gunType[gun_index] == 'J')
  13349. {
  13350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13351. {
  13352. tempIndex = ((gun_index==2) ? 1: 0);
  13353. }
  13354. else
  13355. {
  13356. tempIndex = gun_index;
  13357. }
  13358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13359. {
  13360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13361. {
  13362. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13363. }
  13364. }// End of for CHAdeMO_QUANTITY
  13365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13366. }
  13367. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13368. {
  13369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13370. {
  13371. tempIndex = ((gun_index==2) ? 1: 0);
  13372. }
  13373. else
  13374. {
  13375. tempIndex = gun_index;
  13376. }
  13377. for (int index = 0; index < CCS_QUANTITY; index++)
  13378. {
  13379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13380. {
  13381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13382. }
  13383. }// End of for CCS_QUANTITY
  13384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13385. }
  13386. else if(gunType[gun_index] == 'G')
  13387. {
  13388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13389. {
  13390. tempIndex = ((gun_index==2) ? 1: 0);
  13391. }
  13392. else
  13393. {
  13394. tempIndex = gun_index;
  13395. }
  13396. for (int index = 0; index < GB_QUANTITY; index++)
  13397. {
  13398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13399. {
  13400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13401. }
  13402. }// End of for GB_QUANTITY
  13403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13404. }
  13405. else
  13406. {
  13407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13408. {
  13409. tempIndex = 2;
  13410. }
  13411. else
  13412. {
  13413. tempIndex = gun_index;
  13414. }
  13415. for (int index = 0; index < AC_QUANTITY; index++)
  13416. {
  13417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13418. {
  13419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13420. }
  13421. }// End of for AC_QUANTITY
  13422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13423. }
  13424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13427. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13430. //2.2 Energy.Active.Export.Interval
  13431. //idx_sample=2;
  13432. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13433. if(gunType[gun_index] == 'J')
  13434. {
  13435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13436. {
  13437. tempIndex = ((gun_index==2) ? 1: 0);
  13438. }
  13439. else
  13440. {
  13441. tempIndex = gun_index;
  13442. }
  13443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13444. {
  13445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13446. {
  13447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13448. }
  13449. }// END OF CHAdeMO_QUANTITY
  13450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13451. }
  13452. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13453. {
  13454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13455. {
  13456. tempIndex = ((gun_index==2) ? 1: 0);
  13457. }
  13458. else
  13459. {
  13460. tempIndex = gun_index;
  13461. }
  13462. for (int index = 0; index < CCS_QUANTITY; index++)
  13463. {
  13464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13465. {
  13466. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13467. }
  13468. }// END OF CCS_QUANTITY
  13469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13470. }
  13471. else if(gunType[gun_index] == 'G')
  13472. {
  13473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13474. {
  13475. tempIndex = ((gun_index==2) ? 1: 0);
  13476. }
  13477. else
  13478. {
  13479. tempIndex = gun_index;
  13480. }
  13481. for (int index = 0; index < GB_QUANTITY; index++)
  13482. {
  13483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13484. {
  13485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13486. }
  13487. }// END OF GB_QUANTITY
  13488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13489. }
  13490. else
  13491. {
  13492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13493. {
  13494. tempIndex = 2;
  13495. }
  13496. else
  13497. {
  13498. tempIndex = gun_index;
  13499. }
  13500. for (int index = 0; index < AC_QUANTITY; index++)
  13501. {
  13502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13503. {
  13504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13505. }
  13506. }// END OF AC_QUANTITY
  13507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13508. }
  13509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13512. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13515. //2.3 Power.Active.Export
  13516. //idx_sample=3;
  13517. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13518. if(gunType[gun_index] == 'J')
  13519. {
  13520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13521. {
  13522. tempIndex = ((gun_index==2) ? 1: 0);
  13523. }
  13524. else
  13525. {
  13526. tempIndex = gun_index;
  13527. }
  13528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13529. {
  13530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13531. {
  13532. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13533. }
  13534. } // End for CHAdeMO_QUANTITY
  13535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13536. }
  13537. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13538. {
  13539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13540. {
  13541. tempIndex = ((gun_index==2) ? 1: 0);
  13542. }
  13543. else
  13544. {
  13545. tempIndex = gun_index;
  13546. }
  13547. for (int index = 0; index < CCS_QUANTITY; index++)
  13548. {
  13549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13550. {
  13551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13552. }
  13553. } // END for CCS_QUANTITY
  13554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13555. }
  13556. else if(gunType[gun_index] == 'G')
  13557. {
  13558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13559. {
  13560. tempIndex = ((gun_index==2) ? 1: 0);
  13561. }
  13562. else
  13563. {
  13564. tempIndex = gun_index;
  13565. }
  13566. for (int index = 0; index < GB_QUANTITY; index++)
  13567. {
  13568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13569. {
  13570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13571. }
  13572. }// END for GB_QUANTITY
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13574. }
  13575. else
  13576. {
  13577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13578. {
  13579. tempIndex = 2;
  13580. }
  13581. else
  13582. {
  13583. tempIndex = gun_index;
  13584. }
  13585. for (int index = 0; index < AC_QUANTITY; index++)
  13586. {
  13587. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13588. {
  13589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13590. }
  13591. } // END for AC_QUANTITY
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13593. }
  13594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13597. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13600. //2.4 Voltage
  13601. //idx_sample=4;
  13602. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13603. if(gunType[gun_index] == 'J')
  13604. {
  13605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13606. {
  13607. tempIndex = ((gun_index==2) ? 1: 0);
  13608. }
  13609. else
  13610. {
  13611. tempIndex = gun_index;
  13612. }
  13613. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13614. {
  13615. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13616. {
  13617. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13618. }
  13619. } // END OF FOR CHAdeMO_QUANTITY
  13620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13621. }
  13622. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13623. {
  13624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13625. {
  13626. tempIndex = ((gun_index==2) ? 1: 0);
  13627. }
  13628. else
  13629. {
  13630. tempIndex = gun_index;
  13631. }
  13632. for (int index = 0; index < CCS_QUANTITY; index++)
  13633. {
  13634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13635. {
  13636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13637. }
  13638. } // END OF FOR CCS_QUANTITY
  13639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13640. }
  13641. else if(gunType[gun_index] == 'G')
  13642. {
  13643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13644. {
  13645. tempIndex = ((gun_index==2) ? 1: 0);
  13646. }
  13647. else
  13648. {
  13649. tempIndex = gun_index;
  13650. }
  13651. for (int index = 0; index < GB_QUANTITY; index++)
  13652. {
  13653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13654. {
  13655. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13656. }
  13657. } // END OF FOR GB_QUANTITY
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13659. }
  13660. else
  13661. {
  13662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13663. {
  13664. tempIndex = 2;
  13665. }
  13666. else
  13667. {
  13668. tempIndex = gun_index;
  13669. }
  13670. for (int index = 0; index < AC_QUANTITY; index++)
  13671. {
  13672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13673. {
  13674. 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
  13675. }
  13676. } // END OF FOR AC_QUANTITY
  13677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13678. }
  13679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13682. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13685. //2.5 SoC
  13686. //idx_sample=5;
  13687. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13688. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13689. {
  13690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13691. {
  13692. tempIndex = ((gun_index==2) ? 1: 0);
  13693. }
  13694. else
  13695. {
  13696. tempIndex = gun_index;
  13697. }
  13698. if(gunType[gun_index] == 'J')
  13699. {
  13700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13701. {
  13702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13703. {
  13704. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13705. }
  13706. }
  13707. }
  13708. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13709. {
  13710. for (int index = 0; index < CCS_QUANTITY; index++)
  13711. {
  13712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13713. {
  13714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13715. }
  13716. }
  13717. }
  13718. else if(gunType[gun_index] == 'G')
  13719. {
  13720. for (int index = 0; index < GB_QUANTITY; index++)
  13721. {
  13722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13723. {
  13724. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13725. }
  13726. }
  13727. }
  13728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13734. } // END FOR DC CASE
  13735. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13736. {
  13737. 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\"}]}]}]"
  13738. ,gun_index+1
  13739. ,MESSAGE_TYPE_CALL
  13740. ,guid
  13741. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13745. ,"PowerLoss"
  13746. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13789. );
  13790. }
  13791. else
  13792. {
  13793. 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\"}]}]}]"
  13794. ,gun_index+1
  13795. ,MESSAGE_TYPE_CALL
  13796. ,guid
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13801. ,"PowerLoss"
  13802. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13838. );
  13839. }
  13840. // Check File "TempStopTransaction" Exist
  13841. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13842. {
  13843. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13844. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13845. }
  13846. else
  13847. {
  13848. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13849. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13850. if(log == NULL)
  13851. {
  13852. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13853. return ;
  13854. }
  13855. else
  13856. {
  13857. fclose(log);
  13858. }
  13859. }
  13860. //Add TempStopTransaction | Update TempStopTransaction
  13861. // open file for writing
  13862. FILE *outfile;
  13863. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13864. //DEBUG_INFO("data = %s\n", queuedata);
  13865. fputs(queuedata, outfile);
  13866. fputs("\n", outfile);
  13867. fclose (outfile);
  13868. }
  13869. void checkTempStopTransaction(int gun_index)
  13870. {
  13871. FILE *fptr1;
  13872. char ch;
  13873. char str[1200]={0};
  13874. char guid[37]={0};
  13875. char tempdata[65]={0};
  13876. char connectorStr[2]={0};
  13877. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13878. //TempStopTransaction格式: 槍號,StopTransaction封包
  13879. if (!fptr1)
  13880. {
  13881. //printf(" File not found or unable to open the input file!!\n");
  13882. return ;
  13883. }
  13884. ch=fgetc(fptr1);
  13885. //printf(" Now the content of the file %s is : \n",fname);
  13886. rewind(fptr1);
  13887. if(ch!=EOF)
  13888. {
  13889. // copy all contents to the temporary file except the specific line
  13890. while (fgets(str, 1200, fptr1) != NULL)
  13891. {
  13892. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13893. if(str[0]=='\0')
  13894. {
  13895. break;
  13896. }
  13897. //TempStopTransaction格式: 槍號,StopTransaction封包
  13898. strncpy(connectorStr, str, 1);
  13899. if(atoi(connectorStr) != (gun_index+1))
  13900. {
  13901. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13902. return ;
  13903. }
  13904. //random_uuid(guid);
  13905. strncpy(guid, str+6, 36); //copy guid
  13906. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13907. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13908. {
  13909. DEBUG_INFO("StopTransaction mapitem pass\n");
  13910. }
  13911. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13912. memset(str,0,ARRAY_SIZE(str));
  13913. }
  13914. }
  13915. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13916. fclose(fptr1);
  13917. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13918. }
  13919. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13920. {
  13921. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13922. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13923. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13924. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13925. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13926. }
  13927. int GetWebSocketPingInterval(void)
  13928. {
  13929. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13930. }
  13931. int GetServerSign(void)
  13932. {
  13933. return server_sign;
  13934. }
  13935. void SetServerSign(int value)
  13936. {
  13937. server_sign = value;
  13938. }
  13939. int GetBootNotificationInterval(void)
  13940. {
  13941. return BootNotificationInterval;
  13942. }
  13943. int GetInternetConn(void)
  13944. {
  13945. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13946. }
  13947. void InitialSystemValue(void)
  13948. {
  13949. int connectorIndex = 0;
  13950. //int valueASCII = 0;
  13951. server_cycle_Status = 120;
  13952. gunTotalNumber=0;
  13953. SystemInitial = 0;
  13954. localversion=0;
  13955. BootNotificationInterval = 0;
  13956. authorizeRetryTimes = 0;
  13957. GunStatusInterval = 10;
  13958. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13959. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13960. //Hear Beat
  13961. HeartBeatWithNOResponse = 0;
  13962. HeartBeatCountPerHour = 0;
  13963. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  13964. FirstHeartBeat = 0;
  13965. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  13966. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  13967. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  13968. memset(statusModeChage, 0, sizeof(statusModeChage));
  13969. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13970. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13971. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13972. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13973. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13974. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13975. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13976. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13977. memset(gunType, 0, sizeof(gunType));
  13978. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13979. {
  13980. //check connector / socket type (index: 8, 9, 10)
  13981. for(int index=7; index <10 ; index++)
  13982. {
  13983. if(index != 8)
  13984. {
  13985. // DC Connector
  13986. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13987. {
  13988. SystemInitial = SystemInitial + 1;
  13989. gunTotalNumber = gunTotalNumber + 1;
  13990. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13991. connectorIndex = connectorIndex + 1;
  13992. }
  13993. }
  13994. else
  13995. {
  13996. // AC Connector
  13997. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13998. {
  13999. SystemInitial = SystemInitial + 1;
  14000. gunTotalNumber = gunTotalNumber + 1;
  14001. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14002. connectorIndex = connectorIndex + 1;
  14003. }
  14004. }
  14005. }
  14006. //DEBUG_INFO("DC ...\n");
  14007. }
  14008. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14009. {
  14010. //check connector / socket type (index: 8, 9, 10)
  14011. for(int index=7; index <10 ; index++)
  14012. {
  14013. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14014. {
  14015. SystemInitial = SystemInitial + 1;
  14016. gunTotalNumber = gunTotalNumber + 1;
  14017. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14018. connectorIndex = connectorIndex + 1;
  14019. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14020. }
  14021. }
  14022. }
  14023. //Status && ConnectorPlugIn Setting
  14024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14025. {
  14026. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14027. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14028. }
  14029. for (int index = 0; index < CCS_QUANTITY; index++)
  14030. {
  14031. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14032. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14033. }
  14034. for (int index = 0; index < GB_QUANTITY; index++)
  14035. {
  14036. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14037. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14038. }
  14039. for (int index = 0; index < AC_QUANTITY; index++)
  14040. {
  14041. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14042. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14043. }
  14044. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14045. {
  14046. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14047. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14048. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14049. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14050. }
  14051. // Charger PRE_SYS_MODE
  14052. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  14053. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14054. clientTime.Heartbeat=time((time_t*)NULL);
  14055. sleep(1);
  14056. }
  14057. void LWS_Send(char * str)
  14058. {
  14059. //=====================================================
  14060. // Check InternetConn 0: disconnected, 1: connected
  14061. //====================================================
  14062. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14063. {
  14064. DEBUG_INFO("offline now !!!\n");
  14065. return;
  14066. }
  14067. pthread_mutex_lock(&lock_send);
  14068. memset(SendBuffer, 0, SendBufLen);
  14069. sprintf((char *)SendBuffer, "%s", str);
  14070. pthread_mutex_unlock(&lock_send);
  14071. lws_callback_on_writable(wsi_client);
  14072. lws_service(context, 0);
  14073. //sleep(1);
  14074. }