MessageHandler.c 668 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM 43
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static unsigned char gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  50. static int BootNotificationInterval = 0;
  51. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  52. //===============================
  53. // OCPP auth variable
  54. //===============================
  55. static int authorizeRetryTimes = 0; //number of Retry times
  56. //===============================
  57. // OCPP other variables
  58. //===============================
  59. //int isUpdateRequest = FALSE;
  60. static int HeartBeatWaitTime = 10;
  61. static int FirstHeartBeat = 0;
  62. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  63. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  64. static char CurrentChargingProfileScheduleStr[30] = {0};
  65. //========================================
  66. // OCPP status/previous related variables
  67. //========================================
  68. static int GunStatusInterval = 10;
  69. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  70. static int ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  71. static int CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  72. static int GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  73. static int AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  74. static int ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  75. static int CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  76. static int GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  77. static int AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  78. static int TransactionMessageAttemptsValue = 0;
  79. static int TransactionMessageRetryIntervalValue = 0;
  80. static int TempMeterValueInterval = 0;
  81. static struct OCPPAuthLocalElemet
  82. {
  83. int listVersionInt;
  84. char idTagstr[20];
  85. char parentIdTag[20];
  86. char expiryDate[30];
  87. char idTagstatus[16];
  88. }idTagQuery;
  89. //=============================================
  90. // OCPP HeartBeat Response Not Receive Counts
  91. //============================================
  92. static int HeartBeatWithNOResponse = 0;
  93. static int HeartBeatCountPerHour = 0;
  94. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  95. extern int GetTransactionQueueNum(void);
  96. extern struct Charger_Info Charger;
  97. extern sqlite3 *db;
  98. int TransactionMessageAttemptsGet(void);
  99. int TransactionMessageRetryIntervalGet(void);
  100. int GetOcppConnStatus(void);
  101. void SetOcppConnStatus(uint8_t status);
  102. int setKeyValue(char *key, char *value);
  103. void OCPP_get_TableAuthlocalAllData(void);
  104. void processUnkownKey(void);
  105. struct StructOCPPMeterValue
  106. {
  107. unsigned char TimeStamp[28];
  108. struct StructSampledValue SampledValue[10];
  109. };
  110. struct ClientTime
  111. {
  112. unsigned int Heartbeat;
  113. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  114. unsigned int StartTransaction;
  115. unsigned int StopTransaction;
  116. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq :1; //bit 0,
  126. unsigned char StatusNotificationConf :1; //bit 0,
  127. unsigned char :6; //bit 2~7
  128. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  129. }CpinitiateMsg;
  130. CpinitiateMsg cpinitateMsg;
  131. //GetConfiguration Array
  132. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  134. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  135. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  136. #if 0
  137. static char *ChargePointErrorCodeStr[] = {
  138. MACROSTR(ConnectorLockFailure),
  139. MACROSTR(EVCommunicationError),
  140. MACROSTR(GroundFailure),
  141. MACROSTR(HighTemperature),
  142. MACROSTR(InternalError),
  143. MACROSTR(LocalListConflict),
  144. MACROSTR(NoError),
  145. MACROSTR(OtherError),
  146. MACROSTR(OverCurrentFailure),
  147. MACROSTR(OverVoltage),
  148. MACROSTR(PowerMeterFailure),
  149. MACROSTR(PowerSwitchFailure),
  150. MACROSTR(ReaderFailure),
  151. MACROSTR(ResetFailure),
  152. MACROSTR(UnderVoltage),
  153. MACROSTR(WeakSignal)
  154. };
  155. #endif
  156. static char * ChargePointStatusStr[] = {
  157. MACROSTR(Available),
  158. MACROSTR(Preparing),
  159. MACROSTR(Charging),
  160. MACROSTR(SuspendedEVSE),
  161. MACROSTR(SuspendedEV),
  162. MACROSTR(Finishing),
  163. MACROSTR(Reserved),
  164. MACROSTR(Unavailable),
  165. MACROSTR(Faulted)
  166. };
  167. static char *RegistrationStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Pending),
  170. MACROSTR(Rejected)
  171. };
  172. static char *AvailabilityTypeStr[] = {
  173. MACROSTR(Inoperative),
  174. MACROSTR(Operative)
  175. };
  176. static char *AvailabilityStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected),
  179. MACROSTR(Scheduled)
  180. };
  181. static char *ConfigurationStatusStr[] = {
  182. MACROSTR(Accepted),
  183. MACROSTR(Rejected),
  184. MACROSTR(RebootRequired),
  185. MACROSTR(NotSupported)
  186. };
  187. static char *ClearCacheStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected)
  190. };
  191. static char *ChargingProfilePurposeTypeStr[] = {
  192. MACROSTR(ChargePointMaxProfile),
  193. MACROSTR(TxDefaultProfile),
  194. MACROSTR(TxProfile)
  195. };
  196. static char *ChargingProfileStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected),
  199. MACROSTR(NotSupported)
  200. };
  201. static char *ClearChargingProfileStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Unknown)
  204. };
  205. static char *GetCompositeScheduleStatusStr[] = {
  206. MACROSTR(Accepted),
  207. MACROSTR(Rejected)
  208. };
  209. static char *UpdateTypeStr[] = {
  210. MACROSTR(Differential),
  211. MACROSTR(Full)
  212. };
  213. static char *UpdateStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Failed),
  216. MACROSTR(NotSupported),
  217. MACROSTR(VersionMismatch)
  218. };
  219. static char *RemoteStartStopStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Rejected)
  222. };
  223. static char *ReservationStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Faulted),
  226. MACROSTR(Occupied),
  227. MACROSTR(Rejected),
  228. MACROSTR(Unavailable)
  229. };
  230. static char *ResetTypeStr[] = {
  231. MACROSTR(Hard),
  232. MACROSTR(Soft)
  233. };
  234. static char *ResetStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected)
  237. };
  238. static char * DiagnosticsStatusStr[] = {
  239. MACROSTR(Idle),
  240. MACROSTR(Uploaded),
  241. MACROSTR(UploadFailed),
  242. MACROSTR(Uploading)
  243. };
  244. static char * FirmwareStatusStr[] = {
  245. MACROSTR(Downloaded),
  246. MACROSTR(DownloadFailed),
  247. MACROSTR(Downloading),
  248. MACROSTR(Idle),
  249. MACROSTR(InstallationFailed),
  250. MACROSTR(Installing),
  251. MACROSTR(Installed)
  252. };
  253. static char * MessageTriggerStr[] = {
  254. MACROSTR(BootNotification),
  255. MACROSTR(DiagnosticsStatusNotification),
  256. MACROSTR(FirmwareStatusNotification),
  257. MACROSTR(Heartbeat),
  258. MACROSTR(MeterValues),
  259. MACROSTR(StatusNotification)
  260. };
  261. static char * TriggerMessageStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Rejected),
  264. MACROSTR(NotImplemented)
  265. };
  266. static char * UnlockStatusStr[] = {
  267. MACROSTR(Unlocked),
  268. MACROSTR(UnlockFailed),
  269. MACROSTR(NotSupported)
  270. };
  271. #if 0
  272. static char * StopTransactionReasonStr[] = {
  273. MACROSTR(EmergencyStop),
  274. MACROSTR(EVDisconnected),
  275. MACROSTR(HardReset),
  276. MACROSTR(Local),
  277. MACROSTR(Other),
  278. MACROSTR(PowerLoss),
  279. MACROSTR(Reboot),
  280. MACROSTR(Remote),
  281. MACROSTR(SoftReset),
  282. MACROSTR(UnlockCommand),
  283. MACROSTR(DeAuthorized)
  284. };
  285. #endif
  286. static char * CancelReservationStatusStr[] = {
  287. MACROSTR(Accepted),
  288. MACROSTR(Rejected)
  289. };
  290. static char * ReadingContextStr[] = {
  291. MACROSTR(Interruption.Begin),
  292. MACROSTR(Interruption.End),
  293. MACROSTR(Other),
  294. MACROSTR(Sample.Clock),
  295. MACROSTR(Sample.Periodic),
  296. MACROSTR(Transaction.Begin),
  297. MACROSTR(Transaction.End),
  298. MACROSTR(Trigger)
  299. };
  300. static char * ValueFormatStr[] = {
  301. MACROSTR(Raw),
  302. MACROSTR(SignedData)
  303. };
  304. static char * MeasurandStr[] = {
  305. MACROSTR(Current.Export),
  306. MACROSTR(Current.Import),
  307. MACROSTR(Current.Offered),
  308. MACROSTR(Energy.Active.Export.Register),
  309. MACROSTR(Energy.Active.Import.Register),
  310. MACROSTR(Energy.Reactive.Export.Register),
  311. MACROSTR(Energy.Reactive.Import.Register),
  312. MACROSTR(Energy.Active.Export.Interval),
  313. MACROSTR(Energy.Active.Import.Interval),
  314. MACROSTR(Energy.Reactive.Export.Interval),
  315. MACROSTR(Energy.Reactive.Import.Interval),
  316. MACROSTR(Frequency),
  317. MACROSTR(Power.Active.Export),
  318. MACROSTR(Power.Active.Import),
  319. MACROSTR(Power.Factor),
  320. MACROSTR(Power.Offered),
  321. MACROSTR(Power.Reactive.ExportMACROSTR),
  322. MACROSTR(Power.Reactive.Import),
  323. MACROSTR(RPM),
  324. MACROSTR(SoC),
  325. MACROSTR(Temperature),
  326. MACROSTR(Voltage)
  327. };
  328. static char * LocationStr[] = {
  329. MACROSTR(Body),
  330. MACROSTR(Cable),
  331. MACROSTR(EV),
  332. MACROSTR(Inlet),
  333. MACROSTR(Outlet)
  334. };
  335. static char * PhaseStr[] = {
  336. MACROSTR(L1),
  337. MACROSTR(L2),
  338. MACROSTR(L3),
  339. MACROSTR(N),
  340. MACROSTR(L1-N),
  341. MACROSTR(L2-N),
  342. MACROSTR(L3-N),
  343. MACROSTR(L1-L2),
  344. MACROSTR(L2-L3),
  345. MACROSTR(L3-L1)
  346. };
  347. static char * UnitOfMeasureStr[] = {
  348. MACROSTR(Wh),
  349. MACROSTR(kWh),
  350. MACROSTR(varh),
  351. MACROSTR(kvarh),
  352. MACROSTR(W),
  353. MACROSTR(kW),
  354. MACROSTR(VA),
  355. MACROSTR(kVA),
  356. MACROSTR(var),
  357. MACROSTR(kvar),
  358. MACROSTR(A),
  359. MACROSTR(V),
  360. MACROSTR(Celsius),
  361. MACROSTR(Fahrenheit),
  362. MACROSTR(K),
  363. MACROSTR(Percent)
  364. };
  365. //==========================================
  366. // Check time passed since today
  367. //==========================================
  368. long long DiffTimebWithNow(struct timeb ST)
  369. {
  370. //return milli-second
  371. struct timeb ET;
  372. long long StartTime,StopTime;
  373. ftime(&ET);
  374. StartTime=(long long)ST.time;
  375. StopTime=(long long)ET.time;
  376. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  377. }
  378. int getTimePassSinceToday()
  379. {
  380. int result = -1;
  381. time_t t;
  382. struct tm *tmStartToday;
  383. struct timeb tbStartToday;
  384. t=time(NULL);
  385. tmStartToday=localtime(&t);
  386. tmStartToday->tm_hour = 0;
  387. tmStartToday->tm_min = 0;
  388. tmStartToday->tm_sec = 0;
  389. tbStartToday.time = mktime(tmStartToday);
  390. tbStartToday.millitm = 0;
  391. result = DiffTimebWithNow(tbStartToday)/1000;
  392. return result;
  393. }
  394. //==========================================
  395. // GetCompositeSchedule logic related function
  396. //==========================================
  397. int DiffTimebSec(struct timeb ST, struct timeb ET)
  398. {
  399. //return milli-second
  400. unsigned int StartTime,StopTime;
  401. StartTime=(unsigned int)ST.time;
  402. StopTime=(unsigned int)ET.time;
  403. return (StopTime-StartTime);
  404. }
  405. int DiffTimebWithNowSec(struct timeb ST)
  406. {
  407. //return milli-second
  408. struct timeb ET;
  409. unsigned int StartTime,StopTime;
  410. ftime(&ET);
  411. StartTime=(unsigned int)ST.time;
  412. StopTime=(unsigned int)ET.time;
  413. return (StopTime-StartTime);
  414. }
  415. int getStartStop(uint8_t *start, uint8_t *stop)
  416. {
  417. int result = -1;
  418. struct tm tmStart;
  419. struct timeb tbStart;
  420. struct tm tmStop;
  421. struct timeb tbStop;
  422. 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) &&
  423. (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))
  424. {
  425. tmStart.tm_year -= 1900;
  426. tmStart.tm_mon -= 1;
  427. tbStart.time = mktime(&tmStart);
  428. tbStart.millitm = 0;
  429. tmStop.tm_year -= 1900;
  430. tmStop.tm_mon -= 1;
  431. tbStop.time = mktime(&tmStop);
  432. tbStop.millitm = 0;
  433. result = DiffTimebSec(tbStart, tbStop);
  434. }
  435. else
  436. {
  437. DEBUG_WARN("Start or stop date parsing error.\r\n");
  438. }
  439. return result;
  440. }
  441. int getStartSinceToday(uint8_t *stop)
  442. {
  443. int result = -1;
  444. time_t t;
  445. struct tm *tmStartToday;
  446. struct timeb tbStartToday;
  447. struct tm tmStop;
  448. struct timeb tbStop;
  449. 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))
  450. {
  451. t=time(NULL);
  452. tmStartToday=localtime(&t);
  453. tmStartToday->tm_hour = 0;
  454. tmStartToday->tm_min = 0;
  455. tmStartToday->tm_sec = 0;
  456. tbStartToday.time = mktime(tmStartToday);
  457. tmStop.tm_year -= 1900;
  458. tmStop.tm_mon -= 1;
  459. tbStop.time = mktime(&tmStop);
  460. tbStop.millitm = 0;
  461. result = DiffTimebSec(tbStartToday, tbStop);
  462. }
  463. return result;
  464. }
  465. int getStartSinceWeek(uint8_t *stop)
  466. {
  467. int result = -1;
  468. time_t t;
  469. struct tm *tmStartWeek;
  470. struct timeb tbStartWeek;
  471. struct tm tmStop;
  472. struct timeb tbStop;
  473. 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))
  474. {
  475. t=time(NULL);
  476. tmStartWeek=localtime(&t);
  477. t-=86400*tmStartWeek->tm_wday;
  478. tmStartWeek=localtime(&t);
  479. tmStartWeek->tm_hour = 0;
  480. tmStartWeek->tm_min = 0;
  481. tmStartWeek->tm_sec = 0;
  482. tbStartWeek.time = mktime(tmStartWeek);
  483. tmStop.tm_year -= 1900;
  484. tmStop.tm_mon -= 1;
  485. tbStop.time = mktime(&tmStop);
  486. tbStop.millitm = 0;
  487. result = DiffTimebSec(tbStartWeek, tbStop);
  488. }
  489. return result;
  490. }
  491. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  492. {
  493. FILE *fp;
  494. char profileFileName[128];
  495. char *line = NULL;
  496. size_t len = 0;
  497. time_t CurrentTime;
  498. struct tm *tmComposite;
  499. struct StructChargingProfile maxProfile;
  500. struct StructChargingProfile defaultTxProfile;
  501. struct StructChargingProfile txProfile;
  502. struct StructChargingSchedulePeriod tmpPeriod;
  503. uint8_t limitMax=0;
  504. uint8_t limitDef=0;
  505. uint8_t limitTx=0;
  506. int compositePeriodIdx = 0;
  507. CurrentTime = time(NULL);
  508. tmComposite=localtime(&CurrentTime);
  509. 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);
  510. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  511. compositeProfile->ChargingSchedule.Duration = durationReq;
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. compositeProfile->ChargingProfileId = 0;
  519. compositeProfile->StackLevel = 99 ;
  520. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  521. maxProfile.ChargingProfileId = -1;
  522. defaultTxProfile.ChargingProfileId = -1;
  523. txProfile.ChargingProfileId = -1;
  524. system("yes|rm /tmp/*.json");
  525. system("cp /Storage/OCPP/*.json /tmp");
  526. /*
  527. * Search valid charging profile
  528. */
  529. //DEBUG_INFO("====================================\n");
  530. // Search max profile
  531. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  532. if((access(profileFileName, F_OK))!=-1)
  533. {
  534. fp = fopen(profileFileName, "r");
  535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  536. {
  537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  538. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  539. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  540. }
  541. maxProfile.ChargingProfileId = -1;
  542. maxProfile.StackLevel = -1;
  543. while(getline(&line, &len, fp) != -1)
  544. {
  545. json_object *obj = NULL;
  546. obj = json_tokener_parse(line);
  547. if(is_error(obj))
  548. {
  549. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  550. }
  551. else
  552. {
  553. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  554. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  555. )
  556. {
  557. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  558. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  559. )
  560. {
  561. struct tm tmFrom, tmTo;
  562. struct timeb tbFrom, tbTo;
  563. 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) &&
  564. (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))
  565. {
  566. tmFrom.tm_year -= 1900;
  567. tmFrom.tm_mon -= 1;
  568. tbFrom.time = mktime(&tmFrom);
  569. tmTo.tm_year -= 1900;
  570. tmTo.tm_mon -= 1;
  571. tbTo.time = mktime(&tmTo);
  572. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  573. {
  574. if(maxProfile.ChargingProfileId == -1)
  575. DEBUG_INFO("MaxProfile found.\n");
  576. else
  577. DEBUG_INFO("MaxProfile updated.\n");
  578. // Required item
  579. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  580. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  581. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  582. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  583. 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++)
  584. {
  585. 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"));
  586. 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")));
  587. 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?
  588. 3:
  589. 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")));
  590. }
  591. // Optional item
  592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  593. {
  594. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  595. }
  596. else
  597. {
  598. sprintf((char*)maxProfile.ValidFrom, " ");
  599. }
  600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  601. {
  602. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  603. }
  604. else
  605. {
  606. sprintf((char*)maxProfile.ValidTo, " ");
  607. }
  608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  609. {
  610. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  611. }
  612. else
  613. {
  614. sprintf((char*)maxProfile.RecurrencyKind, " ");
  615. }
  616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  617. {
  618. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  619. }
  620. else
  621. {
  622. maxProfile.TransactionId = -1;
  623. }
  624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  625. {
  626. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  627. }
  628. else
  629. {
  630. maxProfile.ChargingSchedule.Duration = -1;
  631. }
  632. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  633. {
  634. 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")));
  635. }
  636. else
  637. {
  638. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  639. }
  640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  641. {
  642. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  643. }
  644. else
  645. {
  646. maxProfile.ChargingSchedule.MinChargingRate = -1;
  647. }
  648. }
  649. }
  650. }
  651. else
  652. {
  653. if(maxProfile.ChargingProfileId == -1)
  654. DEBUG_INFO("MaxProfile found.\n");
  655. else
  656. DEBUG_INFO("MaxProfile updated.\n");
  657. // Required item
  658. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  659. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  660. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  661. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  662. 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++)
  663. {
  664. 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"));
  665. 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")));
  666. 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?
  667. 3:
  668. 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")));
  669. }
  670. // Optional item
  671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  672. {
  673. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  674. }
  675. else
  676. {
  677. sprintf((char*)maxProfile.ValidFrom, " ");
  678. }
  679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  680. {
  681. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  682. }
  683. else
  684. {
  685. sprintf((char*)maxProfile.ValidTo, " ");
  686. }
  687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  688. {
  689. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  690. }
  691. else
  692. {
  693. sprintf((char*)maxProfile.RecurrencyKind, " ");
  694. }
  695. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  696. {
  697. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  698. }
  699. else
  700. {
  701. maxProfile.TransactionId = -1;
  702. }
  703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  704. {
  705. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  706. }
  707. else
  708. {
  709. maxProfile.ChargingSchedule.Duration = -1;
  710. }
  711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  712. {
  713. 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")));
  714. }
  715. else
  716. {
  717. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  718. }
  719. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  720. {
  721. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  722. }
  723. else
  724. {
  725. maxProfile.ChargingSchedule.MinChargingRate = -1;
  726. }
  727. }
  728. }
  729. }
  730. json_object_put(obj);
  731. }
  732. fclose(fp);
  733. /*
  734. if(maxProfile.ChargingProfileId !=-1)
  735. {
  736. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  737. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  738. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  739. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  740. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  741. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  742. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  743. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  744. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  745. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  746. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  747. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  748. {
  749. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  750. {
  751. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  752. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  753. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  754. }
  755. }
  756. }
  757. else
  758. DEBUG_INFO("MaxProfile not found.\n");
  759. DEBUG_INFO("------------------------------------\n");*/
  760. }
  761. // Search default tx profile
  762. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  763. if((access(profileFileName, F_OK))==-1)
  764. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  765. if((access(profileFileName, F_OK))!=-1)
  766. {
  767. fp = fopen(profileFileName, "r");
  768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  769. {
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  771. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  772. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  773. }
  774. defaultTxProfile.ChargingProfileId = -1;
  775. defaultTxProfile.StackLevel = -1;
  776. while(getline(&line, &len, fp) != -1)
  777. {
  778. json_object *obj = NULL;
  779. obj = json_tokener_parse(line);
  780. if(is_error(obj))
  781. {
  782. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  783. }
  784. else
  785. {
  786. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  787. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  788. )
  789. {
  790. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  791. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  792. )
  793. {
  794. struct tm tmFrom, tmTo;
  795. struct timeb tbFrom, tbTo;
  796. 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) &&
  797. (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))
  798. {
  799. tmFrom.tm_year -= 1900;
  800. tmFrom.tm_mon -= 1;
  801. tbFrom.time = mktime(&tmFrom);
  802. tmTo.tm_year -= 1900;
  803. tmTo.tm_mon -= 1;
  804. tbTo.time = mktime(&tmTo);
  805. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  806. {
  807. if(defaultTxProfile.ChargingProfileId == -1)
  808. DEBUG_INFO("TxDefaultProfile found.\n");
  809. else
  810. DEBUG_INFO("TxDefaultProfile updated.\n");
  811. // Required item
  812. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  813. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  814. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  815. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  816. 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++)
  817. {
  818. 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"));
  819. 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")));
  820. 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?
  821. 3:
  822. 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")));
  823. }
  824. // Optional item
  825. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  826. {
  827. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  828. }
  829. else
  830. {
  831. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  832. }
  833. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  834. {
  835. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  836. }
  837. else
  838. {
  839. sprintf((char*)defaultTxProfile.ValidTo, " ");
  840. }
  841. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  842. {
  843. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  844. }
  845. else
  846. {
  847. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  848. }
  849. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  850. {
  851. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  852. }
  853. else
  854. {
  855. defaultTxProfile.TransactionId = -1;
  856. }
  857. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  858. {
  859. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  860. }
  861. else
  862. {
  863. defaultTxProfile.ChargingSchedule.Duration = -1;
  864. }
  865. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  866. {
  867. 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")));
  868. }
  869. else
  870. {
  871. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  872. }
  873. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  874. {
  875. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  876. }
  877. else
  878. {
  879. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  880. }
  881. }
  882. }
  883. }
  884. else
  885. {
  886. if(defaultTxProfile.ChargingProfileId == -1)
  887. DEBUG_INFO("TxDefaultProfile found.\n");
  888. else
  889. DEBUG_INFO("TxDefaultProfile updated.\n");
  890. // Required item
  891. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  892. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  893. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  894. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  895. 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++)
  896. {
  897. 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"));
  898. 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")));
  899. 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?
  900. 3:
  901. 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")));
  902. }
  903. // Optional item
  904. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  905. {
  906. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  907. }
  908. else
  909. {
  910. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  911. }
  912. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  913. {
  914. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  915. }
  916. else
  917. {
  918. sprintf((char*)defaultTxProfile.ValidTo, " ");
  919. }
  920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  921. {
  922. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  923. }
  924. else
  925. {
  926. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  927. }
  928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  929. {
  930. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  931. }
  932. else
  933. {
  934. defaultTxProfile.TransactionId = -1;
  935. }
  936. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  937. {
  938. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  939. }
  940. else
  941. {
  942. defaultTxProfile.ChargingSchedule.Duration = -1;
  943. }
  944. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  945. {
  946. 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")));
  947. }
  948. else
  949. {
  950. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  951. }
  952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  953. {
  954. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  955. }
  956. else
  957. {
  958. maxProfile.ChargingSchedule.MinChargingRate = -1;
  959. }
  960. }
  961. }
  962. }
  963. json_object_put(obj);
  964. }
  965. fclose(fp);
  966. /*
  967. if(defaultTxProfile.ChargingProfileId != -1)
  968. {
  969. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  970. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  971. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  972. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  973. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  974. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  975. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  976. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  977. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  978. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  979. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  980. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  981. {
  982. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  983. {
  984. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  985. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  986. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  987. }
  988. }
  989. }
  990. else
  991. DEBUG_INFO("TxDefaultProfile not found.\n");
  992. DEBUG_INFO("------------------------------------\n");*/
  993. }
  994. // Search tx profile
  995. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  996. if((access(profileFileName, F_OK))!=-1)
  997. {
  998. fp = fopen(profileFileName, "r");
  999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1000. {
  1001. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1002. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1003. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1004. }
  1005. txProfile.ChargingProfileId = -1;
  1006. txProfile.StackLevel = -1;
  1007. while(getline(&line, &len, fp) != -1)
  1008. {
  1009. json_object *obj = NULL;
  1010. obj = json_tokener_parse(line);
  1011. if(is_error(obj))
  1012. {
  1013. DEBUG_ERROR("Parse txProfile from file error.\n");
  1014. }
  1015. else
  1016. {
  1017. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1018. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1019. )
  1020. {
  1021. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1022. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1023. )
  1024. {
  1025. struct tm tmFrom, tmTo;
  1026. struct timeb tbFrom, tbTo;
  1027. 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) &&
  1028. (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))
  1029. {
  1030. tmFrom.tm_year -= 1900;
  1031. tmFrom.tm_mon -= 1;
  1032. tbFrom.time = mktime(&tmFrom);
  1033. tmTo.tm_year -= 1900;
  1034. tmTo.tm_mon -= 1;
  1035. tbTo.time = mktime(&tmTo);
  1036. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1037. {
  1038. if(txProfile.ChargingProfileId == -1)
  1039. DEBUG_INFO("TxProfile found.\n");
  1040. else
  1041. DEBUG_INFO("TxProfile updated.\n");
  1042. // Required item
  1043. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1044. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1045. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1046. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1047. 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++)
  1048. {
  1049. 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"));
  1050. 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")));
  1051. 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?
  1052. 3:
  1053. 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")));
  1054. }
  1055. // Optional item
  1056. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1057. {
  1058. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1059. }
  1060. else
  1061. {
  1062. sprintf((char*)txProfile.ValidFrom, " ");
  1063. }
  1064. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1065. {
  1066. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1067. }
  1068. else
  1069. {
  1070. sprintf((char*)txProfile.ValidTo, " ");
  1071. }
  1072. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1073. {
  1074. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1075. }
  1076. else
  1077. {
  1078. sprintf((char*)txProfile.RecurrencyKind, " ");
  1079. }
  1080. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1081. {
  1082. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1083. }
  1084. else
  1085. {
  1086. txProfile.TransactionId = -1;
  1087. }
  1088. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1089. {
  1090. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1091. }
  1092. else
  1093. {
  1094. txProfile.ChargingSchedule.Duration = -1;
  1095. }
  1096. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1097. {
  1098. 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")));
  1099. }
  1100. else
  1101. {
  1102. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1103. }
  1104. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1105. {
  1106. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1107. }
  1108. else
  1109. {
  1110. txProfile.ChargingSchedule.MinChargingRate = -1;
  1111. }
  1112. }
  1113. }
  1114. }
  1115. else
  1116. {
  1117. if(txProfile.ChargingProfileId == -1)
  1118. DEBUG_INFO("TxProfile found.\n");
  1119. else
  1120. DEBUG_INFO("TxProfile updated.\n");
  1121. // Required item
  1122. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1123. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1124. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1125. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1126. 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++)
  1127. {
  1128. 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"));
  1129. 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")));
  1130. 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?
  1131. 3:
  1132. 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")));
  1133. }
  1134. // Optional item
  1135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1136. {
  1137. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1138. }
  1139. else
  1140. {
  1141. sprintf((char*)txProfile.ValidFrom, " ");
  1142. }
  1143. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1144. {
  1145. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1146. }
  1147. else
  1148. {
  1149. sprintf((char*)txProfile.ValidTo, " ");
  1150. }
  1151. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1152. {
  1153. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1154. }
  1155. else
  1156. {
  1157. sprintf((char*)txProfile.RecurrencyKind, " ");
  1158. }
  1159. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1160. {
  1161. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1162. }
  1163. else
  1164. {
  1165. txProfile.TransactionId = -1;
  1166. }
  1167. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1168. {
  1169. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1170. }
  1171. else
  1172. {
  1173. txProfile.ChargingSchedule.Duration = -1;
  1174. }
  1175. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1176. {
  1177. 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")));
  1178. }
  1179. else
  1180. {
  1181. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1182. }
  1183. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1184. {
  1185. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1186. }
  1187. else
  1188. {
  1189. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1190. }
  1191. }
  1192. }
  1193. }
  1194. json_object_put(obj);
  1195. }
  1196. fclose(fp);
  1197. /*
  1198. if(defaultTxProfile.ChargingProfileId != -1)
  1199. {
  1200. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1201. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1202. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1203. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1204. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1205. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1206. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1207. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1208. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1209. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1210. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1211. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1212. {
  1213. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1214. {
  1215. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1216. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1217. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1218. }
  1219. }
  1220. }
  1221. else
  1222. DEBUG_INFO("TxProfile not found.\n");*/
  1223. }
  1224. /*
  1225. * Align found profile start schedule & periods
  1226. */
  1227. //DEBUG_INFO("====================================\n");
  1228. /*
  1229. // For local test usage, force modify found profile start schedule info
  1230. 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);
  1231. 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);
  1232. 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);
  1233. */
  1234. if(maxProfile.ChargingProfileId != -1)
  1235. {
  1236. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1237. {
  1238. if(maxProfile.ChargingSchedule.Duration != -1)
  1239. {
  1240. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1241. 0:
  1242. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1243. }
  1244. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1245. {
  1246. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1247. {
  1248. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1249. 0:
  1250. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1251. }
  1252. }
  1253. }
  1254. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1255. {
  1256. if(maxProfile.ChargingSchedule.Duration != -1)
  1257. {
  1258. 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?
  1259. 0:
  1260. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1261. }
  1262. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1263. {
  1264. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1265. {
  1266. 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?
  1267. 0:
  1268. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1269. }
  1270. }
  1271. }
  1272. else
  1273. {
  1274. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1275. {
  1276. if(maxProfile.ChargingSchedule.Duration != -1)
  1277. {
  1278. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1279. 0:
  1280. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1281. }
  1282. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1283. {
  1284. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1285. {
  1286. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1287. 0:
  1288. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1289. }
  1290. }
  1291. }
  1292. else
  1293. {
  1294. if(maxProfile.ChargingSchedule.Duration != -1)
  1295. {
  1296. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1297. 0:
  1298. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1299. }
  1300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1301. {
  1302. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1303. {
  1304. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1305. 0:
  1306. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1307. }
  1308. }
  1309. }
  1310. }
  1311. /*
  1312. DEBUG_INFO("MaxProfile after align.\n");
  1313. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1314. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1315. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1316. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1317. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1318. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1319. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1320. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1321. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1322. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1323. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1325. {
  1326. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1327. {
  1328. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1329. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1330. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1331. }
  1332. }
  1333. DEBUG_INFO("------------------------------------\n");*/
  1334. }
  1335. if(defaultTxProfile.ChargingProfileId != -1)
  1336. {
  1337. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1338. {
  1339. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1340. {
  1341. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1342. 0:
  1343. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1344. }
  1345. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1346. {
  1347. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1348. {
  1349. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1350. 0:
  1351. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1352. }
  1353. }
  1354. }
  1355. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1356. {
  1357. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1358. {
  1359. 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?
  1360. 0:
  1361. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1362. }
  1363. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1364. {
  1365. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1366. {
  1367. 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?
  1368. 0:
  1369. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1370. }
  1371. }
  1372. }
  1373. else
  1374. {
  1375. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1376. {
  1377. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1380. 0:
  1381. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1382. }
  1383. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1384. {
  1385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1386. {
  1387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1388. 0:
  1389. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1390. }
  1391. }
  1392. }
  1393. else
  1394. {
  1395. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1396. {
  1397. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1398. 0:
  1399. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1400. }
  1401. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1402. {
  1403. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1404. {
  1405. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1406. 0:
  1407. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1408. }
  1409. }
  1410. }
  1411. }
  1412. /*
  1413. DEBUG_INFO("defaultTxProfile after align.\n");
  1414. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1415. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1416. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1417. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1418. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1419. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1420. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1421. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1422. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1423. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1424. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1425. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1426. {
  1427. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1428. {
  1429. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1430. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1431. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1432. }
  1433. }
  1434. DEBUG_INFO("------------------------------------\n");*/
  1435. }
  1436. if(txProfile.ChargingProfileId != -1)
  1437. {
  1438. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1439. {
  1440. if(txProfile.ChargingSchedule.Duration != -1)
  1441. {
  1442. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1443. 0:
  1444. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1445. }
  1446. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1447. {
  1448. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1449. {
  1450. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1451. 0:
  1452. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1453. }
  1454. }
  1455. }
  1456. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1457. {
  1458. if(txProfile.ChargingSchedule.Duration != -1)
  1459. {
  1460. 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?
  1461. 0:
  1462. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1463. }
  1464. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1465. {
  1466. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1467. {
  1468. 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?
  1469. 0:
  1470. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1471. }
  1472. }
  1473. }
  1474. else
  1475. {
  1476. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1477. {
  1478. if(txProfile.ChargingSchedule.Duration != -1)
  1479. {
  1480. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1481. 0:
  1482. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1483. }
  1484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1485. {
  1486. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1487. {
  1488. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1489. 0:
  1490. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1491. }
  1492. }
  1493. }
  1494. else
  1495. {
  1496. if(txProfile.ChargingSchedule.Duration != -1)
  1497. {
  1498. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1499. 0:
  1500. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1501. }
  1502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1503. {
  1504. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1505. {
  1506. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1507. 0:
  1508. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1509. }
  1510. }
  1511. }
  1512. }
  1513. /*
  1514. DEBUG_INFO("txProfile after align.\n");
  1515. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1516. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1517. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1518. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1519. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1520. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1521. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1522. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1523. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1524. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1525. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1526. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1527. {
  1528. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1529. {
  1530. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1531. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1532. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1533. }
  1534. }*/
  1535. }
  1536. /*
  1537. * Merge to conposite schedule
  1538. */
  1539. //DEBUG_INFO("====================================\n");
  1540. // Find each profile period quantity
  1541. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1542. {
  1543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1544. limitMax = idx+1;
  1545. }
  1546. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1547. {
  1548. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1549. limitDef = idx+1;
  1550. }
  1551. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1552. {
  1553. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1554. limitTx = idx+1;
  1555. }
  1556. // TxProfile found, composite schedule based on it
  1557. if(txProfile.ChargingProfileId != -1)
  1558. {
  1559. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1560. {
  1561. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1562. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1563. {
  1564. if(maxProfile.ChargingProfileId != -1)
  1565. {
  1566. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1567. {
  1568. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1569. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1570. {
  1571. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1572. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1573. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1574. }
  1575. if(idxMaxPeriod == (limitMax-1))
  1576. {
  1577. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1578. {
  1579. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1580. {
  1581. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1582. compositePeriodIdx++;
  1583. }
  1584. else
  1585. {
  1586. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1587. }
  1588. }
  1589. }
  1590. }
  1591. }
  1592. else
  1593. {
  1594. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1595. {
  1596. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1597. compositePeriodIdx++;
  1598. }
  1599. else
  1600. {
  1601. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1602. }
  1603. }
  1604. }
  1605. if(idxTxPeriod == (limitTx-1))
  1606. {
  1607. if(defaultTxProfile.ChargingProfileId != -1)
  1608. {
  1609. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1610. {
  1611. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1612. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1613. {
  1614. if(maxProfile.ChargingProfileId != -1)
  1615. {
  1616. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1617. {
  1618. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1619. {
  1620. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1621. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1622. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1623. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1624. {
  1625. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1626. {
  1627. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1628. compositePeriodIdx++;
  1629. }
  1630. else
  1631. {
  1632. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1633. }
  1634. }
  1635. break;
  1636. }
  1637. }
  1638. }
  1639. else
  1640. {
  1641. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1642. {
  1643. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1644. compositePeriodIdx++;
  1645. }
  1646. else
  1647. {
  1648. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1658. else if(defaultTxProfile.ChargingProfileId != -1)
  1659. {
  1660. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1661. {
  1662. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1663. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1664. {
  1665. if(maxProfile.ChargingProfileId != -1)
  1666. {
  1667. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1668. {
  1669. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1670. {
  1671. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1673. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1674. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1675. {
  1676. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1677. {
  1678. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1679. compositePeriodIdx++;
  1680. }
  1681. else
  1682. {
  1683. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1684. }
  1685. }
  1686. break;
  1687. }
  1688. }
  1689. }
  1690. else
  1691. {
  1692. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1693. {
  1694. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1695. compositePeriodIdx++;
  1696. }
  1697. else
  1698. {
  1699. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. // Fill other period by MaxProfile
  1706. if(maxProfile.ChargingProfileId != -1)
  1707. {
  1708. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1709. {
  1710. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1711. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  1712. {
  1713. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1714. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1715. {
  1716. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1717. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1718. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1719. }
  1720. if(idxMaxPeriod == (limitMax-1))
  1721. {
  1722. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  1723. {
  1724. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1725. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1726. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1727. }
  1728. if(tmpPeriod.Limit != -1)
  1729. {
  1730. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1731. {
  1732. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1733. {
  1734. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1735. compositePeriodIdx++;
  1736. }
  1737. else
  1738. {
  1739. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1748. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1749. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1753. {
  1754. compositeProfile->ChargingProfileId = 1;
  1755. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1756. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1757. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1758. }
  1759. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1760. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1761. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1762. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1763. }
  1764. if(line)
  1765. free(line);
  1766. }
  1767. //==========================================
  1768. // Init all share memory
  1769. //==========================================
  1770. int InitShareMemory()
  1771. {
  1772. int result = PASS;
  1773. int MeterSMId;
  1774. //creat ShmSysConfigAndInfo
  1775. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1776. {
  1777. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1778. result = FAIL;
  1779. }
  1780. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1781. {
  1782. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1783. result = FAIL;
  1784. }
  1785. else
  1786. {}
  1787. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1788. {
  1789. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1790. result = FAIL;
  1791. }
  1792. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1793. {
  1794. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1795. result = FAIL;
  1796. }
  1797. else
  1798. {}
  1799. //creat ShmPsuData
  1800. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1801. {
  1802. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1803. result = FAIL;
  1804. }
  1805. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1806. {
  1807. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1808. result = FAIL;
  1809. }
  1810. else
  1811. {}
  1812. //creat ShmOCPP16Data
  1813. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1814. {
  1815. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1816. result = FAIL;
  1817. }
  1818. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1819. {
  1820. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1821. result = FAIL;
  1822. }
  1823. else
  1824. {}
  1825. /****************************** For Initial Settings************************************************/
  1826. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1827. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1828. // allocate Configuration memory address
  1829. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1830. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1831. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1832. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1833. //offline MeterValue Interval
  1834. TempMeterValueInterval = 0;
  1835. return result;
  1836. }
  1837. int ProcessShareMemory()
  1838. {
  1839. if(InitShareMemory() == FAIL)
  1840. {
  1841. DEBUG_ERROR("InitShareMemory NG\n");
  1842. if(ShmStatusCodeData!=NULL)
  1843. {
  1844. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1845. }
  1846. sleep(5);
  1847. return FAIL;
  1848. }
  1849. return PASS;
  1850. }
  1851. //---------------------common routine---------------------------//
  1852. int isOFFline(void)
  1853. {
  1854. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1855. {
  1856. if(TempMeterValueInterval >= 2 )
  1857. {
  1858. TempMeterValueInterval = 0;
  1859. return TRUE;
  1860. }
  1861. else
  1862. {
  1863. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1864. return FALSE;
  1865. }
  1866. }
  1867. else
  1868. {
  1869. return FALSE;
  1870. }
  1871. }
  1872. //---------------------------------------------
  1873. // new:
  1874. // enum SYSTEM_STATUS
  1875. // {
  1876. // SYS_MODE_BOOTING = 0,
  1877. // SYS_MODE_IDLE = 1,
  1878. // SYS_MODE_AUTHORIZING = 2,
  1879. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1880. // SYS_MODE_REASSIGN = 4,
  1881. // SYS_MODE_PREPARING = 5,
  1882. // SYS_MODE_PREPARE_FOR_EV = 6,
  1883. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1884. // SYS_MODE_CHARGING = 8,
  1885. // SYS_MODE_TERMINATING = 9,
  1886. // SYS_MODE_COMPLETE = 10,
  1887. // SYS_MODE_ALARM = 11,
  1888. // SYS_MODE_FAULT = 12,
  1889. // SYS_MODE_RESERVATION = 13,
  1890. // SYS_MODE_BOOKING = 14,
  1891. // SYS_MODE_MAINTAIN = 15,
  1892. // SYS_MODE_DEBUG = 16,
  1893. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1894. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1895. // SYS_MODE_UPDATE = 19
  1896. // };
  1897. //
  1898. //
  1899. //-----------------------------------------
  1900. void CheckSystemValue(void)
  1901. {
  1902. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1903. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1904. char filenmae[100]={0};
  1905. char str[100]={0};
  1906. int tempIndex = 0;
  1907. //===============================
  1908. // send Heartbeat
  1909. //===============================
  1910. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1911. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1912. {
  1913. clientTime.Heartbeat=time((time_t*)NULL);
  1914. if(server_sign == TRUE)
  1915. {
  1916. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1917. }
  1918. else
  1919. {
  1920. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  1921. }
  1922. }
  1923. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1924. {
  1925. //parameter for test
  1926. sendHeartbeatRequest(0);
  1927. //==============================================
  1928. // Reset Waiting Time
  1929. //==============================================
  1930. clientTime.Heartbeat=time((time_t*)NULL);
  1931. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1932. }
  1933. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1934. {
  1935. //===============================
  1936. // CSU Trigger Reset Conf
  1937. //===============================
  1938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1939. {
  1940. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1941. }
  1942. //===============================
  1943. // CSU Trigger Authorize Request
  1944. //===============================
  1945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1946. {
  1947. sendAuthorizeRequest(0);
  1948. authorizeRetryTimes = authorizeRetryTimes + 1;
  1949. if(authorizeRetryTimes < 3)
  1950. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1951. }
  1952. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  1953. {
  1954. authorizeRetryTimes = 0;
  1955. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1956. server_sign = FALSE;
  1957. }
  1958. 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))
  1959. {
  1960. sendAuthorizeRequest(0);
  1961. }
  1962. //===============================
  1963. // CSU Trigger Smart Charging Profilw
  1964. //===============================
  1965. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1966. {
  1967. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1968. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  1969. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1970. }
  1971. //==============================================
  1972. // Charger start transaction
  1973. //==============================================
  1974. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1975. {
  1976. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1977. sendStartTransactionRequest(gun_index);
  1978. clientTime.StartTransaction = time((time_t*)NULL);
  1979. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1980. }
  1981. //==============================================
  1982. // Charger stop transaction
  1983. //==============================================
  1984. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1985. {
  1986. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1987. sendStopTransactionRequest(gun_index);
  1988. clientTime.StopTransaction = time((time_t*)NULL);
  1989. }
  1990. //==============================================
  1991. // Charger status report
  1992. //==============================================
  1993. //--- Check Mode Change ---//
  1994. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1995. if(gunType[gun_index] == 'J')
  1996. {
  1997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1998. {
  1999. tempIndex = ((gun_index==2) ? 1: 0);
  2000. }
  2001. else
  2002. {
  2003. tempIndex = gun_index;
  2004. }
  2005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2006. {
  2007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2008. {
  2009. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[gun_index]) )
  2010. {
  2011. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2012. ChademoPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2013. ChademoPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2014. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2015. statusModeChage[gun_index] = TRUE;
  2016. }
  2017. #if 1 // for TempStopTransaction
  2018. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2019. {
  2020. checkTempStopTransaction(gun_index);
  2021. }
  2022. #endif
  2023. }
  2024. }
  2025. }
  2026. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2027. {
  2028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2029. {
  2030. tempIndex = ((gun_index==2) ? 1: 0);
  2031. }
  2032. else
  2033. {
  2034. tempIndex = gun_index;
  2035. }
  2036. for (int index = 0; index < CCS_QUANTITY; index++)
  2037. {
  2038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2039. {
  2040. 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]*/ )
  2041. {
  2042. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2043. CcsPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2044. CcsPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2045. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2046. statusModeChage[gun_index] = TRUE;
  2047. }
  2048. #if 1 // for TempStopTransaction
  2049. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2050. {
  2051. checkTempStopTransaction(gun_index);
  2052. }
  2053. #endif
  2054. }
  2055. }
  2056. }
  2057. else if(gunType[gun_index] == 'G')
  2058. {
  2059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2060. {
  2061. tempIndex = ((gun_index==2) ? 1: 0);
  2062. }
  2063. else
  2064. {
  2065. tempIndex = gun_index;
  2066. }
  2067. for (int index = 0; index < GB_QUANTITY; index++)
  2068. {
  2069. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2070. {
  2071. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[gun_index]) )
  2072. {
  2073. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2074. GbPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2075. GbPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2076. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2077. statusModeChage[gun_index] = TRUE;
  2078. }
  2079. #if 1 // for TempStopTransaction
  2080. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2081. {
  2082. checkTempStopTransaction(gun_index);
  2083. }
  2084. #endif
  2085. }
  2086. }
  2087. }
  2088. else
  2089. {
  2090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2091. {
  2092. tempIndex = 2;
  2093. }
  2094. else
  2095. {
  2096. tempIndex = gun_index;
  2097. }
  2098. for (int index = 0; index < AC_QUANTITY; index++)
  2099. {
  2100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2101. {
  2102. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[gun_index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[gun_index]) )
  2103. {
  2104. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2105. AcPreviousSystemStatus[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2106. AcPreviousConnectorPlugIn[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2107. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2108. statusModeChage[gun_index] = TRUE;
  2109. }
  2110. #if 1 // for TempStopTransaction
  2111. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2112. {
  2113. checkTempStopTransaction(gun_index);
  2114. }
  2115. #endif
  2116. }
  2117. }// END
  2118. }
  2119. if(isWebsocketSendable &&
  2120. (((server_sign == TRUE) && (SystemInitial > 0)) ||
  2121. ((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))))) )
  2122. {
  2123. if(SystemInitial > 0)
  2124. SystemInitial = SystemInitial -1;
  2125. sendStatusNotificationRequest(gun_index);
  2126. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2127. statusModeChage[gun_index] = FALSE;
  2128. }
  2129. //==============================================
  2130. // Meter report
  2131. //==============================================
  2132. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) ||
  2133. (((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)))
  2134. {
  2135. //check Transaction active
  2136. if(gunType[gun_index] == 'J')
  2137. {
  2138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2139. {
  2140. tempIndex = ((gun_index==2) ? 1: 0);
  2141. }
  2142. else
  2143. {
  2144. tempIndex = gun_index;
  2145. }
  2146. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2147. {
  2148. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2149. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2150. {
  2151. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2152. {
  2153. reqSampleMeter[gun_index] = 1;
  2154. }
  2155. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2156. {
  2157. reqClockAlignMeter[gun_index] = 1;
  2158. }
  2159. }
  2160. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2161. {
  2162. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2163. if((access(filenmae,F_OK))!=-1)
  2164. {
  2165. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2166. sprintf(str,"rm -f %s",filenmae);
  2167. system(str);
  2168. }
  2169. }
  2170. }// End for CHAdeMO
  2171. }
  2172. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2173. {
  2174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2175. {
  2176. tempIndex = ((gun_index==2) ? 1: 0);
  2177. }
  2178. else
  2179. {
  2180. tempIndex = gun_index;
  2181. }
  2182. for (int index = 0; index < CCS_QUANTITY; index++)
  2183. {
  2184. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2185. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2186. {
  2187. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2188. {
  2189. reqSampleMeter[gun_index] = 1;
  2190. }
  2191. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2192. {
  2193. reqClockAlignMeter[gun_index] = 1;
  2194. }
  2195. }
  2196. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2197. {
  2198. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2199. if((access(filenmae,F_OK))!=-1)
  2200. {
  2201. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2202. sprintf(str,"rm -f %s",filenmae);
  2203. system(str);
  2204. }
  2205. }
  2206. } // End for CCS
  2207. }
  2208. else if(gunType[gun_index] == 'G')
  2209. {
  2210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2211. {
  2212. tempIndex = ((gun_index==2) ? 1: 0);
  2213. }
  2214. else
  2215. {
  2216. tempIndex = gun_index;
  2217. }
  2218. for (int index = 0; index < GB_QUANTITY; index++)
  2219. {
  2220. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2221. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2222. {
  2223. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2224. {
  2225. reqSampleMeter[gun_index] = 1;
  2226. }
  2227. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2228. {
  2229. reqClockAlignMeter[gun_index] = 1;
  2230. }
  2231. }
  2232. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2233. {
  2234. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2235. if((access(filenmae,F_OK))!=-1)
  2236. {
  2237. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2238. sprintf(str,"rm -f %s",filenmae);
  2239. system(str);
  2240. }
  2241. }
  2242. }// End for GB
  2243. }
  2244. else
  2245. {
  2246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2247. {
  2248. tempIndex = 2;
  2249. }
  2250. else
  2251. {
  2252. tempIndex = gun_index;
  2253. }
  2254. for (int index = 0; index < AC_QUANTITY; index++)
  2255. {
  2256. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2257. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2258. {
  2259. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2260. {
  2261. reqSampleMeter[gun_index] = 1;
  2262. }
  2263. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2264. {
  2265. reqClockAlignMeter[gun_index] = 1;
  2266. }
  2267. }
  2268. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2269. {
  2270. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2271. if((access(filenmae,F_OK))!=-1)
  2272. {
  2273. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2274. sprintf(str,"rm -f %s",filenmae);
  2275. system(str);
  2276. }
  2277. }
  2278. }//End for AC
  2279. }
  2280. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2281. if(reqSampleMeter[gun_index] == 1)
  2282. {
  2283. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2284. storeTempStopTransaction(gun_index);
  2285. }
  2286. else if(reqClockAlignMeter[gun_index] == 1)
  2287. {
  2288. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2289. }
  2290. sleep(1);
  2291. }
  2292. //==============================================
  2293. // Check Connector reserved
  2294. //==============================================
  2295. //===============================
  2296. // Check if Reserve is expired
  2297. //===============================
  2298. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2299. {
  2300. double diff_t;
  2301. struct tm tp;
  2302. // current time
  2303. time_t t = time(NULL);
  2304. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2305. tp.tm_isdst = -1;
  2306. time_t utc = mktime(&tp);
  2307. diff_t = difftime(utc, t);
  2308. if(diff_t <= 0)
  2309. {
  2310. DEBUG_INFO("reserve expired.\n");
  2311. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2312. }
  2313. }//END OF Check if Reserve is expired
  2314. //==========================================
  2315. // csu trigger FirmwareStatusNotificationReq
  2316. //==========================================
  2317. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2318. {
  2319. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2320. }
  2321. //==========================================
  2322. // csu trigger CancelReservationConf
  2323. //==========================================
  2324. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2325. {
  2326. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2327. }
  2328. //==========================================
  2329. // csu trigger ChangeAvailabilityConf
  2330. //==========================================
  2331. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2332. {
  2333. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2334. }
  2335. //==========================================
  2336. // csu trigger UnlockConnectorConf
  2337. //==========================================
  2338. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2339. {
  2340. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2341. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2342. }
  2343. //==========================================
  2344. // csu trigger ReserveNowConf
  2345. //==========================================
  2346. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2347. {
  2348. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2349. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2350. }
  2351. //==========================================
  2352. // csu trigger DataTransferReq
  2353. //==========================================
  2354. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2355. {
  2356. sendDataTransferRequest(gun_index);
  2357. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2358. }
  2359. }
  2360. }
  2361. //==========================================
  2362. // send request routine
  2363. //==========================================
  2364. int sendAuthorizeRequest(int gun_index)
  2365. {
  2366. mtrace();
  2367. int result = FAIL;
  2368. char message[100]={0};
  2369. char guid[37];
  2370. char tempdata[65]={0};
  2371. DEBUG_INFO("sendAuthorizeRequest...\n");
  2372. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2373. //Local Authorize
  2374. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2375. {
  2376. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2378. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2379. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2380. result = PASS;
  2381. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2382. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2383. authorizeRetryTimes = 0;
  2384. return result;
  2385. }
  2386. 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))||
  2387. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2388. {
  2389. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2390. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2391. {
  2392. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2393. {
  2394. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2395. }
  2396. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2397. {
  2398. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2399. }
  2400. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2401. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2402. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2403. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2404. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2405. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2406. authorizeRetryTimes = 0;
  2407. return result;
  2408. }
  2409. else
  2410. {
  2411. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2412. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2413. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2414. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2415. result = PASS;
  2416. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2417. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2418. authorizeRetryTimes = 0;
  2419. return result;
  2420. }
  2421. }
  2422. //initailize struct Authorize
  2423. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2424. //get data from shared memory
  2425. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2426. random_uuid(guid);
  2427. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2428. LWS_Send(message);
  2429. sprintf(tempdata, "Authorize,%d", gun_index);
  2430. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2431. {
  2432. result = PASS;
  2433. DEBUG_INFO("Authorize mapItem pass\n");
  2434. }
  2435. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2436. return result;
  2437. }
  2438. int sendBootNotificationRequest(void)
  2439. {
  2440. mtrace();
  2441. int result = FAIL;
  2442. char message[500]={0}, payload[700]={0};
  2443. char guid[37]={0};
  2444. char tempdata[65]={0};
  2445. int IsGunCharging = FALSE;
  2446. //check Transaction active
  2447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2448. {
  2449. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2450. {
  2451. IsGunCharging = TRUE;
  2452. }
  2453. }
  2454. for (int index = 0; index < CCS_QUANTITY; index++)
  2455. {
  2456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2457. {
  2458. IsGunCharging = TRUE;
  2459. }
  2460. }
  2461. for (int index = 0; index < GB_QUANTITY; index++)
  2462. {
  2463. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2464. {
  2465. IsGunCharging = TRUE;
  2466. }
  2467. }
  2468. for (int index = 0; index < AC_QUANTITY; index++)
  2469. {
  2470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2471. {
  2472. IsGunCharging = TRUE;
  2473. }
  2474. }
  2475. if(IsGunCharging == TRUE)
  2476. {
  2477. server_sign = TRUE;
  2478. return result;
  2479. }
  2480. // Fill BootNotification fields
  2481. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2482. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2483. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2484. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2485. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2486. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2487. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2488. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2489. ShmOCPP16Data->ChargeBoxId
  2490. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2491. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2492. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2493. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2494. ,ShmOCPP16Data->BootNotification.CpIccid
  2495. ,ShmOCPP16Data->BootNotification.CpImsi);
  2496. random_uuid(guid);
  2497. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2498. LWS_Send(message);
  2499. sprintf(tempdata, "BootNotification,0");
  2500. 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*/)
  2501. {
  2502. result = PASS;
  2503. }
  2504. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2505. strcpy(queuedata,message);
  2506. return result;
  2507. }
  2508. int sendDataTransferRequest(int gun_index)
  2509. {
  2510. mtrace();
  2511. char message[1000]={0};
  2512. char guid[37]={0};
  2513. char tempdata[65]={0};
  2514. int result = FAIL;
  2515. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2516. random_uuid(guid);
  2517. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2518. MESSAGE_TYPE_CALL,
  2519. guid,
  2520. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2521. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2522. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2523. LWS_Send(message);
  2524. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2525. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2526. {
  2527. result = PASS;
  2528. DEBUG_INFO("DataTransfer mapItem pass\n");
  2529. }
  2530. return result;
  2531. }
  2532. int sendDiagnosticsStatusNotificationRequest(char *status)
  2533. {
  2534. mtrace();
  2535. int result = FAIL;
  2536. char message[110]={0};
  2537. char guid[37]={0};
  2538. char tempdata[65]={0};
  2539. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2540. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2541. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2542. random_uuid(guid);
  2543. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2544. LWS_Send(message);
  2545. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2546. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2547. {
  2548. result = PASS;
  2549. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2550. }
  2551. //#ifdef SystemLogMessage
  2552. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2553. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2554. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2555. //#endif
  2556. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2557. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2558. //record status
  2559. if(strcmp(status,"Idle")==0)
  2560. {
  2561. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2562. }
  2563. else if(strcmp(status,"Uploaded")==0)
  2564. {
  2565. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2566. }
  2567. else if(strcmp(status,"UploadFailed")==0)
  2568. {
  2569. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2570. }
  2571. else if(strcmp(status,"Uploading")==0)
  2572. {
  2573. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2574. }
  2575. return result;
  2576. }
  2577. int sendFirmwareStatusNotificationRequest(char *status)
  2578. {
  2579. mtrace();
  2580. int result = FAIL;
  2581. char message[110]={0};
  2582. char guid[37]={0};
  2583. char tempdata[65]={0};
  2584. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2585. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2586. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2587. random_uuid(guid);
  2588. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2589. LWS_Send(message);
  2590. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2591. 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*/)
  2592. {
  2593. result = PASS;
  2594. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2595. }
  2596. //#ifdef SystemLogMessage
  2597. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2598. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2599. //#endif
  2600. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2601. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2602. //record status
  2603. if(strcmp(status,"Downloaded")==0)
  2604. {
  2605. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2606. }
  2607. else if(strcmp(status,"DownloadFailed")==0)
  2608. {
  2609. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2610. }
  2611. else if(strcmp(status,"Downloading")==0)
  2612. {
  2613. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2614. }
  2615. else if(strcmp(status,"Idle")==0)
  2616. {
  2617. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2618. }
  2619. else if(strcmp(status,"InstallationFailed")==0)
  2620. {
  2621. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2622. }
  2623. else if(strcmp(status,"Installing")==0)
  2624. {
  2625. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2626. }
  2627. else if(strcmp(status,"Installed")==0)
  2628. {
  2629. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2630. }
  2631. return result;
  2632. }
  2633. int sendHeartbeatRequest(int gun_index)
  2634. {
  2635. mtrace();
  2636. int result = FAIL;
  2637. char message[80]={0};
  2638. char guid[37]={0};
  2639. char tempdata[65]={0};
  2640. random_uuid(guid);
  2641. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2642. , MESSAGE_TYPE_CALL
  2643. , guid );
  2644. LWS_Send(message);
  2645. sprintf(tempdata, "Heartbeat,%d", 0);
  2646. 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*/)
  2647. {
  2648. result = PASS;
  2649. }
  2650. return result;
  2651. }
  2652. int sendStartTransactionRequest(int gun_index)
  2653. {
  2654. mtrace();
  2655. int result = FAIL;
  2656. char message[250]={0};
  2657. char guid[37]={0};
  2658. struct timeval tmnow;
  2659. struct tm *tm;
  2660. char buf[28];//, usec_buf[6];
  2661. char tempdata[65]={0};
  2662. int tempIndex = 0;
  2663. DEBUG_INFO("sendStartTransactionRequest...\n");
  2664. gettimeofday(&tmnow, NULL);
  2665. time_t t;
  2666. t = time(NULL);
  2667. /*UTC time and date*/
  2668. tm = gmtime(&t);
  2669. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2670. #if 0 // remove temporally
  2671. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2672. strcat(buf,".");
  2673. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2674. strcat(buf,usec_buf);
  2675. #endif
  2676. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2677. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2678. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2679. // clear StartTransaction Response
  2680. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2681. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2682. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2683. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2684. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2685. if(gunType[gun_index] == 'J')
  2686. {
  2687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2688. {
  2689. tempIndex = ((gun_index==2) ? 1: 0);
  2690. }
  2691. else
  2692. {
  2693. tempIndex = gun_index;
  2694. }
  2695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2696. {
  2697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2698. {
  2699. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2700. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2701. }
  2702. }
  2703. }
  2704. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2705. {
  2706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2707. {
  2708. tempIndex = ((gun_index==2) ? 1: 0);
  2709. }
  2710. else
  2711. {
  2712. tempIndex = gun_index;
  2713. }
  2714. for (int index = 0; index < CCS_QUANTITY; index++)
  2715. {
  2716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2717. {
  2718. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2719. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2720. }
  2721. }
  2722. }
  2723. else if(gunType[gun_index] == 'G')
  2724. {
  2725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2726. {
  2727. tempIndex = ((gun_index==2) ? 1: 0);
  2728. }
  2729. else
  2730. {
  2731. tempIndex = gun_index;
  2732. }
  2733. for (int index = 0; index < GB_QUANTITY; index++)
  2734. {
  2735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2736. {
  2737. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2738. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2739. }
  2740. }
  2741. }
  2742. else
  2743. {
  2744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2745. {
  2746. tempIndex = 2;
  2747. }
  2748. else
  2749. {
  2750. tempIndex = gun_index;
  2751. }
  2752. for (int index = 0; index < AC_QUANTITY; index++)
  2753. {
  2754. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2755. {
  2756. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2757. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2758. }
  2759. }
  2760. }
  2761. random_uuid(guid);
  2762. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2763. {
  2764. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2765. , gun_index +1
  2766. , MESSAGE_TYPE_CALL
  2767. , guid
  2768. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2769. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2770. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2771. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2772. }
  2773. else
  2774. {
  2775. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2776. , gun_index +1
  2777. , MESSAGE_TYPE_CALL
  2778. , guid
  2779. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2780. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2781. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2782. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2783. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2784. }
  2785. #if 1
  2786. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2787. 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*/)
  2788. {
  2789. result = PASS;
  2790. }
  2791. #endif
  2792. strcpy(queuedata, message);
  2793. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2794. /*
  2795. if(GetTransactionQueueNum() == 1)
  2796. {
  2797. LWS_Send(message + 2);
  2798. }*/
  2799. return result;
  2800. }
  2801. int sendStatusNotificationRequest(int gun_index)
  2802. {
  2803. mtrace();
  2804. int result = FAIL;
  2805. char message[600]={0};
  2806. char guid[37];
  2807. int currentStatus = 0;
  2808. struct timeval tmnow;
  2809. struct tm *tm;
  2810. char buf[28];//, usec_buf[6];
  2811. char tempdata[65]={0};
  2812. int tempIndex = 0;
  2813. gettimeofday(&tmnow, NULL);
  2814. time_t t;
  2815. t = time(NULL);
  2816. /*UTC time and date*/
  2817. tm = gmtime(&t);
  2818. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2819. #if 0 // remove temporally
  2820. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2821. strcat(buf,".");
  2822. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2823. strcat(buf,usec_buf);
  2824. #endif
  2825. printf("%s",buf);
  2826. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2827. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2828. // it's option
  2829. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2830. /*
  2831. enum _SYSTEM_STATUS
  2832. {
  2833. S_BOOTING = 0,
  2834. S_IDLE, = 1
  2835. S_AUTHORIZING, =2
  2836. S_REASSIGN_CHECK, =3
  2837. S_REASSIGN, =4
  2838. S_PRECHARGE, =5
  2839. S_PREPARING_FOR_EV, =6
  2840. S_PREPARING_FOR_EVSE, =7
  2841. S_CHARGING, =8
  2842. S_TERMINATING, =9
  2843. S_COMPLETE, =10
  2844. S_ALARM, =11
  2845. S_FAULT =12
  2846. }
  2847. */
  2848. //check Transaction active
  2849. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2850. if(gunType[gun_index] == 'J')
  2851. {
  2852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2853. {
  2854. tempIndex = ((gun_index==2) ? 1: 0);
  2855. }
  2856. else
  2857. {
  2858. tempIndex = gun_index;
  2859. }
  2860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2861. {
  2862. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2863. {
  2864. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2865. {
  2866. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2867. {
  2868. currentStatus = 1; //OCPP Status: Preparing
  2869. }
  2870. else
  2871. {
  2872. currentStatus = 0; //OCPP Status: Available
  2873. }
  2874. }
  2875. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2876. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2877. ) //S_PRECHARGE
  2878. {
  2879. currentStatus = 1; //OCPP Status: Preparing
  2880. }
  2881. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2882. {
  2883. currentStatus = 2; //OCPP Status: Charging
  2884. }
  2885. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2886. {
  2887. currentStatus = 5; //OCPP Status: Finishing
  2888. }
  2889. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2890. {
  2891. currentStatus = 4; //OCPP Status: SuspendedEV
  2892. }
  2893. 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
  2894. {
  2895. currentStatus = 7; //OCPP Status: Unavailable
  2896. }
  2897. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2898. {
  2899. currentStatus = 8; //OCPP Status: Faulted
  2900. }
  2901. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2902. {
  2903. currentStatus = 6; //OCPP Status: Reserved
  2904. }
  2905. } //end of the same index
  2906. }//end of for CHAdeMO_QUANTITY
  2907. }
  2908. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < CCS_QUANTITY; index++)
  2919. {
  2920. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2921. {
  2922. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2923. {
  2924. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  2925. {
  2926. currentStatus = 1; //OCPP Status: Preparing
  2927. }
  2928. else
  2929. {
  2930. currentStatus = 0; //OCPP Status: Available
  2931. }
  2932. }
  2933. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2934. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2935. ) //S_PRECHARGE
  2936. {
  2937. currentStatus = 1; //OCPP Status: Preparing
  2938. }
  2939. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2940. {
  2941. currentStatus = 2; //OCPP Status: Charging
  2942. }
  2943. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2944. {
  2945. currentStatus = 5; //OCPP Status: Finishing
  2946. }
  2947. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  2948. {
  2949. currentStatus = 4; //OCPP Status: SuspendedEV
  2950. }
  2951. 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
  2952. {
  2953. currentStatus = 7; //OCPP Status : Unavailable
  2954. }
  2955. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2956. {
  2957. currentStatus = 8; //OCPP Status: Faulted
  2958. }
  2959. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2960. {
  2961. currentStatus = 6; //OCPP Status: Reserved
  2962. }
  2963. } //end of the same index
  2964. } // end of for CCS_QUANTITY
  2965. }
  2966. else if(gunType[gun_index] == 'G')
  2967. {
  2968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2969. {
  2970. tempIndex = ((gun_index==2) ? 1: 0);
  2971. }
  2972. else
  2973. {
  2974. tempIndex = gun_index;
  2975. }
  2976. for (int index = 0; index < GB_QUANTITY; index++)
  2977. {
  2978. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2979. {
  2980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2981. {
  2982. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2983. {
  2984. currentStatus = 1; //OCPP Status: Preparing
  2985. }
  2986. else
  2987. {
  2988. currentStatus = 0; //OCPP Status: Available
  2989. }
  2990. }
  2991. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2992. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2993. ) //S_PRECHARGE
  2994. {
  2995. currentStatus = 1; //OCPP Status: Preparing
  2996. }
  2997. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2998. {
  2999. currentStatus = 2; //OCPP Status: Charging
  3000. }
  3001. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3002. {
  3003. currentStatus = 5; //OCPP Status: Finishing
  3004. }
  3005. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3006. {
  3007. currentStatus = 4; //OCPP Status: SuspendedEV
  3008. }
  3009. 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
  3010. {
  3011. currentStatus = 7; //OCPP Status: Unavailable
  3012. }
  3013. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3014. {
  3015. currentStatus = 8; //OCPP Status: Faulted
  3016. }
  3017. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3018. {
  3019. currentStatus = 6; //OCPP Status: Reserved
  3020. }
  3021. } //end of the same index
  3022. } // end of for GB_QUANTITY
  3023. }
  3024. else
  3025. {
  3026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3027. {
  3028. tempIndex = 2;
  3029. }
  3030. else
  3031. {
  3032. tempIndex = gun_index;
  3033. }
  3034. for (int index = 0; index < AC_QUANTITY; index++)
  3035. {
  3036. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3037. {
  3038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3039. {
  3040. 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))
  3041. {
  3042. currentStatus = 1; //OCPP Status: Preparing
  3043. }
  3044. else
  3045. {
  3046. currentStatus = 0; //OCPP Status: Available
  3047. }
  3048. }
  3049. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3050. {
  3051. currentStatus = 1; //OCPP Status: Preparing
  3052. }
  3053. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3054. {
  3055. currentStatus = 2; //OCPP Status: Charging
  3056. }
  3057. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3058. {
  3059. currentStatus = 5; //OCPP Status: Finishing
  3060. }
  3061. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3062. {
  3063. currentStatus = 4; //OCPP Status: SuspendedEV
  3064. }
  3065. 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
  3066. {
  3067. currentStatus = 7; //OCPP Status: Unavailable
  3068. }
  3069. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3070. {
  3071. currentStatus = 8; //OCPP Status: Faulted
  3072. }
  3073. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3074. {
  3075. currentStatus = 6; //OCPP Status: Reserved
  3076. }
  3077. }//end of the same index
  3078. }//end of for AC_QUANTITY
  3079. }
  3080. //it's option
  3081. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3082. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3083. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3084. random_uuid(guid);
  3085. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3086. , MESSAGE_TYPE_CALL
  3087. , guid
  3088. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3089. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3090. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3091. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3092. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3093. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3094. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3095. LWS_Send(message);
  3096. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3097. 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*/)
  3098. {
  3099. //DEBUG_ERROR("statusNotification mapitem pass");
  3100. result = PASS;
  3101. }
  3102. return result;
  3103. }
  3104. int sendStopTransactionRequest(int gun_index)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. //char message[1500]={0};
  3109. char guid[37]={0};
  3110. char tempdata[65]={0};
  3111. int tempIndex = 0;
  3112. //int idx_sample=0;
  3113. DEBUG_ERROR("sendStopTransactionRequest \n");
  3114. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3115. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3116. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3117. if(gunType[gun_index] == 'J')
  3118. {
  3119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3120. {
  3121. tempIndex = ((gun_index==2) ? 1: 0);
  3122. }
  3123. else
  3124. {
  3125. tempIndex = gun_index;
  3126. }
  3127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3128. {
  3129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3130. {
  3131. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3132. }
  3133. }// END OF CHAdeMO_QUANTITY
  3134. }
  3135. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3136. {
  3137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3138. {
  3139. tempIndex = ((gun_index==2) ? 1: 0);
  3140. }
  3141. else
  3142. {
  3143. tempIndex = gun_index;
  3144. }
  3145. for (int index = 0; index < CCS_QUANTITY; index++)
  3146. {
  3147. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3148. {
  3149. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3150. }
  3151. }// END OF CCS_QUANTITY
  3152. }
  3153. else if(gunType[gun_index] == 'G')
  3154. {
  3155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3156. {
  3157. tempIndex = ((gun_index==2) ? 1: 0);
  3158. }
  3159. else
  3160. {
  3161. tempIndex = gun_index;
  3162. }
  3163. for (int index = 0; index < GB_QUANTITY; index++)
  3164. {
  3165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3166. {
  3167. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3168. }
  3169. }// END OF GB_QUANTITY
  3170. }
  3171. else
  3172. {
  3173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3174. {
  3175. tempIndex = 2;
  3176. }
  3177. else
  3178. {
  3179. tempIndex = gun_index;
  3180. }
  3181. for (int index = 0; index < AC_QUANTITY; index++)
  3182. {
  3183. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3184. {
  3185. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3186. }
  3187. }// END OF AC_QUANTITY
  3188. }
  3189. //====================================== Stop Transaction Time =====================================================
  3190. struct timeval tmnow;
  3191. struct tm *tm;
  3192. char buf[28];//, usec_buf[6];
  3193. gettimeofday(&tmnow, NULL);
  3194. time_t t;
  3195. t = time(NULL);
  3196. /*UTC time and date*/
  3197. tm = gmtime(&t);
  3198. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3200. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3201. random_uuid(guid);
  3202. /***********************************transactionData******************************************************/
  3203. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3205. //=================================
  3206. // Transaction_Begin
  3207. //=================================
  3208. //============================================ Energy.Active.Export.Interval ================================
  3209. //idx_sample=0;
  3210. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3213. 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*/]);
  3214. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3215. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3216. {
  3217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3218. }
  3219. else
  3220. {
  3221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3222. }
  3223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3225. //=================================
  3226. // Transaction_End
  3227. //=================================
  3228. // ================================= Current.Import L1 ===============================================
  3229. //idx_sample=1;
  3230. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3231. if(gunType[gun_index] == 'J')
  3232. {
  3233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3234. {
  3235. tempIndex = ((gun_index==2) ? 1: 0);
  3236. }
  3237. else
  3238. {
  3239. tempIndex = gun_index;
  3240. }
  3241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3242. {
  3243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3244. {
  3245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3246. }
  3247. }// End of for CHAdeMO_QUANTITY
  3248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3249. }
  3250. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3251. {
  3252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3253. {
  3254. tempIndex = ((gun_index==2) ? 1: 0);
  3255. }
  3256. else
  3257. {
  3258. tempIndex = gun_index;
  3259. }
  3260. for (int index = 0; index < CCS_QUANTITY; index++)
  3261. {
  3262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3263. {
  3264. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3265. }
  3266. }// End of for CCS_QUANTITY
  3267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3268. }
  3269. else if(gunType[gun_index] == 'G')
  3270. {
  3271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3272. {
  3273. tempIndex = ((gun_index==2) ? 1: 0);
  3274. }
  3275. else
  3276. {
  3277. tempIndex = gun_index;
  3278. }
  3279. for (int index = 0; index < GB_QUANTITY; index++)
  3280. {
  3281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3282. {
  3283. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3284. }
  3285. }// End of for GB_QUANTITY
  3286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3287. }
  3288. else
  3289. {
  3290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3291. {
  3292. tempIndex = 2;
  3293. }
  3294. else
  3295. {
  3296. tempIndex = gun_index;
  3297. }
  3298. for (int index = 0; index < AC_QUANTITY; index++)
  3299. {
  3300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3301. {
  3302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3303. }
  3304. }// End of for AC_QUANTITY
  3305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3306. }
  3307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3312. // ================================= Energy.Active.Import.Interval ==============================================
  3313. //idx_sample=2;
  3314. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3315. if(gunType[gun_index] == 'J')
  3316. {
  3317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3318. {
  3319. tempIndex = ((gun_index==2) ? 1: 0);
  3320. }
  3321. else
  3322. {
  3323. tempIndex = gun_index;
  3324. }
  3325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3326. {
  3327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3328. {
  3329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3330. }
  3331. }// END OF CHAdeMO_QUANTITY
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3333. }
  3334. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3335. {
  3336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3337. {
  3338. tempIndex = ((gun_index==2) ? 1: 0);
  3339. }
  3340. else
  3341. {
  3342. tempIndex = gun_index;
  3343. }
  3344. for (int index = 0; index < CCS_QUANTITY; index++)
  3345. {
  3346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3347. {
  3348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3349. }
  3350. }// END OF CCS_QUANTITY
  3351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3352. }
  3353. else if(gunType[gun_index] == 'G')
  3354. {
  3355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3356. {
  3357. tempIndex = ((gun_index==2) ? 1: 0);
  3358. }
  3359. else
  3360. {
  3361. tempIndex = gun_index;
  3362. }
  3363. for (int index = 0; index < GB_QUANTITY; index++)
  3364. {
  3365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3366. {
  3367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3368. }
  3369. }// END OF GB_QUANTITY
  3370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3371. }
  3372. else
  3373. {
  3374. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3375. {
  3376. tempIndex = 2;
  3377. }
  3378. else
  3379. {
  3380. tempIndex = gun_index;
  3381. }
  3382. for (int index = 0; index < AC_QUANTITY; index++)
  3383. {
  3384. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3385. {
  3386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3387. }
  3388. }// END OF AC_QUANTITY
  3389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3390. }
  3391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3396. //=================================== Power.Active.Export ==================================================
  3397. //idx_sample=3;
  3398. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3399. if(gunType[gun_index] == 'J')
  3400. {
  3401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3402. {
  3403. tempIndex = ((gun_index==2) ? 1: 0);
  3404. }
  3405. else
  3406. {
  3407. tempIndex = gun_index;
  3408. }
  3409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3410. {
  3411. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3412. {
  3413. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3414. }
  3415. } // End for CHAdeMO_QUANTITY
  3416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3417. }
  3418. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3419. {
  3420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3421. {
  3422. tempIndex = ((gun_index==2) ? 1: 0);
  3423. }
  3424. else
  3425. {
  3426. tempIndex = gun_index;
  3427. }
  3428. for (int index = 0; index < CCS_QUANTITY; index++)
  3429. {
  3430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3431. {
  3432. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3433. }
  3434. } // END for CCS_QUANTITY
  3435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3436. }
  3437. else if(gunType[gun_index] == 'G')
  3438. {
  3439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3440. {
  3441. tempIndex = ((gun_index==2) ? 1: 0);
  3442. }
  3443. else
  3444. {
  3445. tempIndex = gun_index;
  3446. }
  3447. for (int index = 0; index < GB_QUANTITY; index++)
  3448. {
  3449. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3450. {
  3451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3452. }
  3453. }// END for GB_QUANTITY
  3454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3455. }
  3456. else
  3457. {
  3458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3459. {
  3460. tempIndex = 2;
  3461. }
  3462. else
  3463. {
  3464. tempIndex = gun_index;
  3465. }
  3466. for (int index = 0; index < AC_QUANTITY; index++)
  3467. {
  3468. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3469. {
  3470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3471. }
  3472. } // END for AC_QUANTITY
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3474. }
  3475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3480. //============================ Voltage L1 ====================================
  3481. //idx_sample=4;
  3482. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3483. if(gunType[gun_index] == 'J')
  3484. {
  3485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3486. {
  3487. tempIndex = ((gun_index==2) ? 1: 0);
  3488. }
  3489. else
  3490. {
  3491. tempIndex = gun_index;
  3492. }
  3493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3494. {
  3495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3496. {
  3497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3498. }
  3499. } // END OF FOR CHAdeMO_QUANTITY
  3500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3501. }
  3502. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3503. {
  3504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3505. {
  3506. tempIndex = ((gun_index==2) ? 1: 0);
  3507. }
  3508. else
  3509. {
  3510. tempIndex = gun_index;
  3511. }
  3512. for (int index = 0; index < CCS_QUANTITY; index++)
  3513. {
  3514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3515. {
  3516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3517. }
  3518. } // END OF FOR CCS_QUANTITY
  3519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3520. }
  3521. else if(gunType[gun_index] == 'G')
  3522. {
  3523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3524. {
  3525. tempIndex = ((gun_index==2) ? 1: 0);
  3526. }
  3527. else
  3528. {
  3529. tempIndex = gun_index;
  3530. }
  3531. for (int index = 0; index < GB_QUANTITY; index++)
  3532. {
  3533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3534. {
  3535. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3536. }
  3537. } // END OF FOR GB_QUANTITY
  3538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3539. }
  3540. else
  3541. {
  3542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3543. {
  3544. tempIndex = 2;
  3545. }
  3546. else
  3547. {
  3548. tempIndex = gun_index;
  3549. }
  3550. for (int index = 0; index < AC_QUANTITY; index++)
  3551. {
  3552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3553. {
  3554. 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
  3555. }
  3556. } // END OF FOR AC_QUANTITY
  3557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3558. }
  3559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3564. //====================== SoC ================================
  3565. //idx_sample=5;
  3566. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3567. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3568. {
  3569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3570. {
  3571. tempIndex = ((gun_index==2) ? 1: 0);
  3572. }
  3573. else
  3574. {
  3575. tempIndex = gun_index;
  3576. }
  3577. if(gunType[gun_index] == 'J')
  3578. {
  3579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3580. {
  3581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3582. {
  3583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3584. }
  3585. }
  3586. }
  3587. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3588. {
  3589. for (int index = 0; index < CCS_QUANTITY; index++)
  3590. {
  3591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3592. {
  3593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3594. }
  3595. }
  3596. }
  3597. else if(gunType[gun_index] == 'G')
  3598. {
  3599. for (int index = 0; index < GB_QUANTITY; index++)
  3600. {
  3601. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3602. {
  3603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3604. }
  3605. }
  3606. }
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3613. } // END FOR DC CASE
  3614. // ================================= Current.Import L2 ===============================================
  3615. //idx_sample=6;
  3616. // AC 3 phse L2 current
  3617. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3618. {
  3619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3620. {
  3621. tempIndex = 2;
  3622. }
  3623. else
  3624. {
  3625. tempIndex = gun_index;
  3626. }
  3627. for (int index = 0; index < AC_QUANTITY; index++)
  3628. {
  3629. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3630. {
  3631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3632. }
  3633. }// End of for AC_QUANTITY
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3635. }
  3636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3641. // ================================= Current.Import L3 ===============================================
  3642. //idx_sample=7;
  3643. // AC 3 phse L3 current
  3644. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3645. {
  3646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3647. {
  3648. tempIndex = 2;
  3649. }
  3650. else
  3651. {
  3652. tempIndex = gun_index;
  3653. }
  3654. for (int index = 0; index < AC_QUANTITY; index++)
  3655. {
  3656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3657. {
  3658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3659. }
  3660. }// End of for AC_QUANTITY
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3662. }
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3668. //============================ Voltage L2 ====================================
  3669. //idx_sample=8;
  3670. // AC 3 phse L2 voltage
  3671. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3672. {
  3673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3674. {
  3675. tempIndex = 2;
  3676. }
  3677. else
  3678. {
  3679. tempIndex = gun_index;
  3680. }
  3681. for (int index = 0; index < AC_QUANTITY; index++)
  3682. {
  3683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3684. {
  3685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3686. }
  3687. } // END OF FOR AC_QUANTITY
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3689. }
  3690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3695. //============================ Voltage L3 ====================================
  3696. //idx_sample=8;
  3697. // AC 3 phse L3 voltage
  3698. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3699. {
  3700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3701. {
  3702. tempIndex = 2;
  3703. }
  3704. else
  3705. {
  3706. tempIndex = gun_index;
  3707. }
  3708. for (int index = 0; index < AC_QUANTITY; index++)
  3709. {
  3710. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3711. {
  3712. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3713. }
  3714. } // END OF FOR AC_QUANTITY
  3715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3716. }
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3722. //================================================ Message create ====================================================
  3723. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3724. {
  3725. 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\"}]}]}]"
  3726. ,gun_index+1
  3727. ,MESSAGE_TYPE_CALL
  3728. ,guid
  3729. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3730. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3731. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3733. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3734. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3777. );
  3778. }
  3779. else
  3780. {
  3781. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3782. {
  3783. 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\"}]}]}]"
  3784. ,gun_index+1
  3785. ,MESSAGE_TYPE_CALL
  3786. ,guid
  3787. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3788. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3789. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3791. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3792. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3828. );
  3829. }
  3830. else
  3831. {
  3832. 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\"},{\"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\"}]}]}]"
  3833. ,gun_index+1
  3834. ,MESSAGE_TYPE_CALL
  3835. ,guid
  3836. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3837. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3838. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3840. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3841. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  3905. );
  3906. }
  3907. }
  3908. #if 1 // for TempStopTransaction
  3909. //Delete TempStopTransaction
  3910. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3911. {
  3912. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3913. }
  3914. #endif
  3915. #if 1
  3916. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3917. if(hashmap_operation(0, guid, tempdata) == 1)
  3918. {
  3919. result = PASS;
  3920. DEBUG_INFO("StopTransaction mapitem pass\n");
  3921. }
  3922. #endif
  3923. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3924. /*
  3925. if(GetTransactionQueueNum() == 1)
  3926. {
  3927. LWS_Send(queuedata+2);
  3928. }*/
  3929. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3930. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  3931. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  3932. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3933. {
  3934. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3935. }
  3936. //for test
  3937. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3938. return result;
  3939. }
  3940. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  3941. {
  3942. mtrace();
  3943. int result = FAIL;
  3944. char guid[37]={0};
  3945. char tempdata[65]={0};
  3946. int tempIndex = 0;
  3947. DEBUG_INFO("sendMeterValuesRequest ...\n");
  3948. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  3949. /*
  3950. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3951. {
  3952. DEBUG_INFO("NOT SENT METER Vlaue\n");
  3953. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  3954. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  3955. return result;
  3956. }*/
  3957. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  3958. {
  3959. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3960. }
  3961. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3962. //set value
  3963. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  3964. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  3965. random_uuid(guid);
  3966. //UTC Date time
  3967. struct timeval tmnow;
  3968. struct tm *tm;
  3969. char buf[28];//, usec_buf[6];
  3970. gettimeofday(&tmnow, NULL);
  3971. time_t t;
  3972. t = time(NULL);
  3973. /*UTC time and date*/
  3974. tm = gmtime(&t);
  3975. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  3977. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3978. //idx_sample=0;
  3979. //********************************(1)Current.Import L1************************************************/
  3980. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3981. if(gunType[gun_index] == 'J')
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3984. {
  3985. tempIndex = ((gun_index==2) ? 1: 0);
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3992. {
  3993. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3994. {
  3995. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  3996. }
  3997. }
  3998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  3999. }
  4000. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4001. {
  4002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4003. {
  4004. tempIndex = ((gun_index==2) ? 1: 0);
  4005. }
  4006. else
  4007. {
  4008. tempIndex = gun_index;
  4009. }
  4010. for (int index = 0; index < CCS_QUANTITY; index++)
  4011. {
  4012. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4013. {
  4014. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4015. }
  4016. }
  4017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4018. }
  4019. else if(gunType[gun_index] == 'G')
  4020. {
  4021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4022. {
  4023. tempIndex = ((gun_index==2) ? 1: 0);
  4024. }
  4025. else
  4026. {
  4027. tempIndex = gun_index;
  4028. }
  4029. for (int index = 0; index < GB_QUANTITY; index++)
  4030. {
  4031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4032. {
  4033. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4034. }
  4035. }
  4036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4037. }
  4038. else
  4039. {
  4040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4041. {
  4042. tempIndex = 2;
  4043. }
  4044. else
  4045. {
  4046. tempIndex = gun_index;
  4047. }
  4048. for (int index = 0; index < AC_QUANTITY; index++)
  4049. {
  4050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4051. {
  4052. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4053. }
  4054. }
  4055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4056. }
  4057. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4060. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4061. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4062. //idx_sample=1;
  4063. //********************************(2)Energy.Active.Import.Register ************************************************/
  4064. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4065. if(gunType[gun_index] == 'J')
  4066. {
  4067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4068. {
  4069. tempIndex = ((gun_index==2) ? 1: 0);
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4076. {
  4077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4078. {
  4079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4080. }
  4081. }
  4082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4083. }
  4084. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4085. {
  4086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4087. {
  4088. tempIndex = ((gun_index==2) ? 1: 0);
  4089. }
  4090. else
  4091. {
  4092. tempIndex = gun_index;
  4093. }
  4094. for (int index = 0; index < CCS_QUANTITY; index++)
  4095. {
  4096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4097. {
  4098. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4099. }
  4100. }
  4101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4102. }
  4103. else if(gunType[gun_index] == 'G')
  4104. {
  4105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4106. {
  4107. tempIndex = ((gun_index==2) ? 1: 0);
  4108. }
  4109. else
  4110. {
  4111. tempIndex = gun_index;
  4112. }
  4113. for (int index = 0; index < GB_QUANTITY; index++)
  4114. {
  4115. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4116. {
  4117. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4118. }
  4119. }
  4120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4121. }
  4122. else
  4123. {
  4124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4125. {
  4126. tempIndex = 2;
  4127. }
  4128. else
  4129. {
  4130. tempIndex = gun_index;
  4131. }
  4132. for (int index = 0; index < AC_QUANTITY; index++)
  4133. {
  4134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4135. {
  4136. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4137. }
  4138. }
  4139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4140. }
  4141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4144. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4146. //idx_sample=2;
  4147. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4148. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4149. if(gunType[gun_index] == 'J')
  4150. {
  4151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4152. {
  4153. tempIndex = ((gun_index==2) ? 1: 0);
  4154. }
  4155. else
  4156. {
  4157. tempIndex = gun_index;
  4158. }
  4159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4162. {
  4163. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4164. }
  4165. } // END OF FOR CHAdeMO_QUANTITY
  4166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4167. }
  4168. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4171. {
  4172. tempIndex = ((gun_index==2) ? 1: 0);
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < CCS_QUANTITY; index++)
  4179. {
  4180. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4181. {
  4182. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4183. }
  4184. } // END OF CCS_QUANTITY
  4185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4186. }
  4187. else if(gunType[gun_index] == 'G')
  4188. {
  4189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4190. {
  4191. tempIndex = ((gun_index==2) ? 1: 0);
  4192. }
  4193. else
  4194. {
  4195. tempIndex = gun_index;
  4196. }
  4197. for (int index = 0; index < GB_QUANTITY; index++)
  4198. {
  4199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4200. {
  4201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4202. }
  4203. } // END OF GB_QUANTITY
  4204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4205. }
  4206. else
  4207. {
  4208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4209. {
  4210. tempIndex = 2;
  4211. }
  4212. else
  4213. {
  4214. tempIndex = gun_index;
  4215. }
  4216. for (int index = 0; index < AC_QUANTITY; index++)
  4217. {
  4218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4219. {
  4220. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4221. }
  4222. }
  4223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4224. }
  4225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4230. //idx_sample=3;
  4231. //********************************(4)Power.Active.Import************************************************/
  4232. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4233. if(gunType[gun_index] == 'J')
  4234. {
  4235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4236. {
  4237. tempIndex = ((gun_index==2) ? 1: 0);
  4238. }
  4239. else
  4240. {
  4241. tempIndex = gun_index;
  4242. }
  4243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4244. {
  4245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4246. {
  4247. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4248. }
  4249. } // END OF FOR
  4250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4251. }
  4252. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4253. {
  4254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4255. {
  4256. tempIndex = ((gun_index==2) ? 1: 0);
  4257. }
  4258. else
  4259. {
  4260. tempIndex = gun_index;
  4261. }
  4262. for (int index = 0; index < CCS_QUANTITY; index++)
  4263. {
  4264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4265. {
  4266. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4267. }
  4268. }
  4269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4270. }
  4271. else if(gunType[gun_index] == 'G')
  4272. {
  4273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4274. {
  4275. tempIndex = ((gun_index==2) ? 1: 0);
  4276. }
  4277. else
  4278. {
  4279. tempIndex = gun_index;
  4280. }
  4281. for (int index = 0; index < GB_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4284. {
  4285. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4286. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4287. }
  4288. }
  4289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4290. }
  4291. else
  4292. {
  4293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4294. {
  4295. tempIndex = 2;
  4296. }
  4297. else
  4298. {
  4299. tempIndex = gun_index;
  4300. }
  4301. for (int index = 0; index < AC_QUANTITY; index++)
  4302. {
  4303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4304. {
  4305. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4306. }
  4307. }
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4309. }
  4310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4315. //idx_sample=4;
  4316. //***********************************************(5)VOLTAGE L1******************************************************/
  4317. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4318. if(gunType[gun_index] == 'J')
  4319. {
  4320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4321. {
  4322. tempIndex = ((gun_index==2) ? 1: 0);
  4323. }
  4324. else
  4325. {
  4326. tempIndex = gun_index;
  4327. }
  4328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4329. {
  4330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4331. {
  4332. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4333. }
  4334. }
  4335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4336. }
  4337. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4340. {
  4341. tempIndex = ((gun_index==2) ? 1: 0);
  4342. }
  4343. else
  4344. {
  4345. tempIndex = gun_index;
  4346. }
  4347. for (int index = 0; index < CCS_QUANTITY; index++)
  4348. {
  4349. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4350. {
  4351. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4352. }
  4353. }
  4354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4355. }
  4356. else if(gunType[gun_index] == 'G')
  4357. {
  4358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4359. {
  4360. tempIndex = ((gun_index==2) ? 1: 0);
  4361. }
  4362. else
  4363. {
  4364. tempIndex = gun_index;
  4365. }
  4366. for (int index = 0; index < GB_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4371. }
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4374. }
  4375. else
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4378. {
  4379. tempIndex = 2;
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < AC_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4388. {
  4389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4390. }
  4391. }
  4392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4393. }
  4394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4399. //***********************************************(6)SOC******************************************************/
  4400. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4401. {
  4402. //idx_sample=5;
  4403. //sampledValue = NULL;
  4404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4405. {
  4406. tempIndex = ((gun_index==2) ? 1: 0);
  4407. }
  4408. else
  4409. {
  4410. tempIndex = gun_index;
  4411. }
  4412. if(gunType[gun_index] == 'J')
  4413. {
  4414. //tempIndex = ((gun_index==2) ? 1: 0);
  4415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4418. {
  4419. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4420. }
  4421. }
  4422. }
  4423. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4424. {
  4425. //tempIndex = ((gun_index==2) ? 1: 0);
  4426. for (int index = 0; index < CCS_QUANTITY; index++)
  4427. {
  4428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4429. {
  4430. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4431. }
  4432. }
  4433. }
  4434. else if(gunType[gun_index] == 'G')
  4435. {
  4436. //tempIndex = ((gun_index==2) ? 1: 0);
  4437. for (int index = 0; index < GB_QUANTITY; index++)
  4438. {
  4439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4440. {
  4441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4442. }
  4443. }
  4444. }
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4451. }
  4452. //********************************(7)Current.Import L2************************************************/
  4453. // Only for AC 3 phase
  4454. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4455. {
  4456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4457. {
  4458. tempIndex = 2;
  4459. }
  4460. else
  4461. {
  4462. tempIndex = gun_index;
  4463. }
  4464. for (int index = 0; index < AC_QUANTITY; index++)
  4465. {
  4466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4467. {
  4468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4469. }
  4470. }
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4472. }
  4473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4478. //********************************(8)Current.Import L3************************************************/
  4479. // Only for AC 3 phase
  4480. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4481. {
  4482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4483. {
  4484. tempIndex = 2;
  4485. }
  4486. else
  4487. {
  4488. tempIndex = gun_index;
  4489. }
  4490. for (int index = 0; index < AC_QUANTITY; index++)
  4491. {
  4492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4493. {
  4494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4495. }
  4496. }
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4498. }
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4504. //***********************************************(9)VOLTAGE L2******************************************************/
  4505. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4506. {
  4507. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4508. {
  4509. tempIndex = 2;
  4510. }
  4511. else
  4512. {
  4513. tempIndex = gun_index;
  4514. }
  4515. for (int index = 0; index < AC_QUANTITY; index++)
  4516. {
  4517. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4518. {
  4519. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4520. }
  4521. }
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4523. }
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4529. //***********************************************(10)VOLTAGE L3******************************************************/
  4530. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4531. {
  4532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4533. {
  4534. tempIndex = 2;
  4535. }
  4536. else
  4537. {
  4538. tempIndex = gun_index;
  4539. }
  4540. for (int index = 0; index < AC_QUANTITY; index++)
  4541. {
  4542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4543. {
  4544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4545. }
  4546. }
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4548. }
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4554. // Message create ====================================================================================================
  4555. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4556. {
  4557. 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\"}]}]}]"
  4558. ,gun_index + 1
  4559. ,MESSAGE_TYPE_CALL
  4560. ,guid
  4561. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4562. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4563. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4564. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4606. );
  4607. }
  4608. else
  4609. {
  4610. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4611. {
  4612. 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\"}]}]}]"
  4613. ,gun_index + 1
  4614. ,MESSAGE_TYPE_CALL
  4615. ,guid
  4616. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4617. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4618. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4654. );
  4655. }
  4656. else
  4657. {
  4658. 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\"},{\"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\"}]}]}]"
  4659. ,gun_index + 1
  4660. ,MESSAGE_TYPE_CALL
  4661. ,guid
  4662. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4663. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4664. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4728. );
  4729. }
  4730. }
  4731. // Put request guid to hash map
  4732. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4733. 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*/)
  4734. {
  4735. result = PASS;
  4736. DEBUG_INFO("MeterValues mapitem pass\n");
  4737. }
  4738. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4739. /*
  4740. if(GetTransactionQueueNum() == 1)
  4741. {
  4742. LWS_Send(queuedata +2);
  4743. }*/
  4744. return result;
  4745. }
  4746. //==========================================
  4747. // send confirm routine
  4748. //==========================================
  4749. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4750. {
  4751. mtrace();
  4752. int result = FAIL;
  4753. char message[100]={0};
  4754. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4755. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4756. LWS_Send(message);
  4757. result = TRUE;
  4758. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4759. return result;
  4760. }
  4761. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4762. {
  4763. mtrace();
  4764. int result = FAIL;
  4765. char message[100]={0};
  4766. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4767. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4768. LWS_Send(message);
  4769. result = TRUE;
  4770. return result;
  4771. }
  4772. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4773. {
  4774. mtrace();
  4775. int result = FAIL;
  4776. char message[100]={0};
  4777. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4778. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4779. LWS_Send(message);
  4780. result = TRUE;
  4781. return result;
  4782. }
  4783. int sendClearCacheConfirmation(char *uuid,char *payload)
  4784. {
  4785. mtrace();
  4786. int result = FAIL;
  4787. char message[500]={0};
  4788. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4789. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4790. LWS_Send(message);
  4791. return result;
  4792. }
  4793. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4794. {
  4795. mtrace();
  4796. int result = FAIL;
  4797. char message[500]={0};
  4798. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4799. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4800. LWS_Send(message);
  4801. return result;
  4802. }
  4803. int sendDataTransferConfirmation(char *uuid,char *payload)
  4804. {
  4805. mtrace();
  4806. char statusStr[20]={0};
  4807. char dataStr[10]={0};
  4808. char sstr[20]={0};
  4809. int c = 0;
  4810. char *loc;
  4811. int result = FAIL;
  4812. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4813. /**********************status**************************/
  4814. loc = strstr(payload, "status");
  4815. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4816. c = 0;
  4817. while (loc[3+strlen("status")+c] != '\"')
  4818. {
  4819. sstr[c] = loc[3+strlen("status")+c];
  4820. c++;
  4821. }
  4822. sstr[c] = '\0';
  4823. strcpy(statusStr, sstr);
  4824. /**********************data**************************/
  4825. loc = strstr(payload, "data");
  4826. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4827. c = 0;
  4828. while (loc[3+strlen("data")+c] != '\"')
  4829. {
  4830. sstr[c] = loc[3+strlen("data")+c];
  4831. c++;
  4832. }
  4833. sstr[c] = '\0';
  4834. strcpy(dataStr, sstr);
  4835. return result;
  4836. }
  4837. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4838. {
  4839. mtrace();
  4840. int result = FAIL;
  4841. char message[1000]={0};
  4842. int CompositeScheduleIndex = 0;
  4843. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4844. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4845. if(nPeriod == 0)
  4846. {
  4847. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4848. {
  4849. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4850. ,MESSAGE_TYPE_CALLRESULT
  4851. ,uuid
  4852. ,payload
  4853. ,connectorIdInt);
  4854. }
  4855. else
  4856. {
  4857. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4858. ,MESSAGE_TYPE_CALLRESULT
  4859. ,uuid
  4860. ,payload
  4861. ,connectorIdInt
  4862. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4863. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4864. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4865. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4866. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4867. }
  4868. }
  4869. else
  4870. {
  4871. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4872. ,MESSAGE_TYPE_CALLRESULT
  4873. ,uuid
  4874. ,payload
  4875. ,connectorIdInt
  4876. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4877. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4878. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4879. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4880. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4881. {
  4882. if (idx_sample == 0)
  4883. {
  4884. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4885. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4886. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4887. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4888. }
  4889. else
  4890. {
  4891. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4892. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4893. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4894. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4895. }
  4896. }
  4897. sprintf(message + strlen(message), "]}}]");
  4898. }
  4899. LWS_Send(message);
  4900. result = TRUE;
  4901. return result;
  4902. }
  4903. int sendGetConfigurationConfirmation(char *uuid)
  4904. {
  4905. mtrace();
  4906. int result = FAIL;
  4907. int MaxKeySupported = 0;
  4908. int sentConfigurationNumber= 0;
  4909. int sentunConfigurationNumber= 0;
  4910. char message[4000]={0};
  4911. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4912. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4913. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4914. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4915. ,MESSAGE_TYPE_CALLRESULT
  4916. ,uuid );
  4917. //configuration key
  4918. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4919. {
  4920. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4921. {
  4922. if (sentConfigurationNumber == 0)
  4923. {
  4924. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4925. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4926. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4927. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4928. }
  4929. else
  4930. {
  4931. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4932. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4933. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4934. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4935. }
  4936. sentConfigurationNumber = sentConfigurationNumber + 1;
  4937. }
  4938. }
  4939. sprintf(message + strlen(message), "]");
  4940. if(UnknownKeynum != 0)
  4941. {
  4942. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4943. //unkown key
  4944. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4945. {
  4946. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4947. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4948. if(sentunConfigurationNumber == 0)
  4949. {
  4950. sprintf(message + strlen(message), "\"%s\""
  4951. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4952. }
  4953. else
  4954. {
  4955. sprintf(message + strlen(message), ",\"%s\""
  4956. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4957. }
  4958. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4959. }
  4960. sprintf(message + strlen(message), "]");
  4961. }
  4962. sprintf(message + strlen(message), "}]");
  4963. LWS_Send(message);
  4964. return result;
  4965. }
  4966. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4967. {
  4968. mtrace();
  4969. int result = FAIL;
  4970. char message[400]={0};
  4971. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4972. if(strcmp(payload,"")==0)
  4973. {
  4974. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4975. }
  4976. else
  4977. {
  4978. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4979. }
  4980. LWS_Send(message);
  4981. result = TRUE;
  4982. return result;
  4983. }
  4984. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4985. {
  4986. mtrace();
  4987. int result = FAIL;
  4988. char message[80]={0};
  4989. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4990. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4991. LWS_Send(message);
  4992. result = TRUE;
  4993. return result;
  4994. }
  4995. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4996. {
  4997. mtrace();
  4998. int result = FAIL;
  4999. char message[80]={0};
  5000. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5002. LWS_Send(message);
  5003. result = TRUE;
  5004. return result;
  5005. }
  5006. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5007. {
  5008. mtrace();
  5009. int result = FAIL;
  5010. char message[80]={0};
  5011. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5012. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5013. LWS_Send(message);
  5014. result = TRUE;
  5015. return result;
  5016. }
  5017. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5018. {
  5019. mtrace();
  5020. int result = FAIL;
  5021. char message[80]={0};
  5022. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5023. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5024. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5025. LWS_Send(message);
  5026. result = TRUE;
  5027. return result;
  5028. }
  5029. int sendResetConfirmation(char *uuid,char *payload)
  5030. {
  5031. mtrace();
  5032. int result = FAIL;
  5033. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5034. char message[80]={0};
  5035. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5036. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5037. LWS_Send(message);
  5038. result = TRUE;
  5039. return result;
  5040. }
  5041. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5042. {
  5043. mtrace();
  5044. int result = FAIL;
  5045. char message[500]={0};
  5046. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5047. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5048. LWS_Send(message);
  5049. result = TRUE;
  5050. return result;
  5051. }
  5052. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5053. {
  5054. mtrace();
  5055. int result = FAIL;
  5056. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5057. char message[80]={0};
  5058. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5059. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5060. LWS_Send(message);
  5061. result = TRUE;
  5062. return result;
  5063. }
  5064. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5065. {
  5066. mtrace();
  5067. int result = FAIL;
  5068. char message[80]={0};
  5069. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5070. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5071. LWS_Send(message);
  5072. result = TRUE;
  5073. return result;
  5074. }
  5075. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5076. {
  5077. mtrace();
  5078. int result = FAIL;
  5079. char message[80]={0};
  5080. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5081. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5082. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5083. LWS_Send(message);
  5084. result = TRUE;
  5085. return result;
  5086. }
  5087. int sendUpdateFirmwareConfirmation(char *uuid)
  5088. {
  5089. mtrace();
  5090. int result = FAIL;
  5091. char message[60]={0};
  5092. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5093. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5094. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5095. LWS_Send(message);
  5096. result = TRUE;
  5097. return result;
  5098. }
  5099. //==========================================
  5100. // send CallError routine
  5101. //==========================================
  5102. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5103. {
  5104. mtrace();
  5105. char message[220]={0};
  5106. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5107. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5108. LWS_Send(message);
  5109. }
  5110. //==========================================
  5111. // Handle server request routine Start
  5112. //==========================================
  5113. int handleCancelReservationRequest(char *uuid, char *payload)
  5114. {
  5115. mtrace();
  5116. int result = FAIL;
  5117. int gunNO = 0;
  5118. int reservationIdInt =0;
  5119. char comfirmstr[20];
  5120. DEBUG_INFO("handleCancelReservationRequest...\n");
  5121. json_object *CancelReservation;
  5122. CancelReservation = json_tokener_parse(payload);
  5123. if(!is_error(CancelReservation))
  5124. {
  5125. // Required data
  5126. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5127. }
  5128. json_object_put(CancelReservation);
  5129. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5130. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5131. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5132. //check Transaction active
  5133. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5135. {
  5136. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5137. {
  5138. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5139. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5140. if(gunType[2] == 'J')
  5141. {
  5142. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5143. }
  5144. else
  5145. {
  5146. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5147. }
  5148. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5149. goto end;
  5150. }
  5151. }
  5152. for (int index = 0; index < CCS_QUANTITY; index++)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5155. {
  5156. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5157. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5158. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5159. {
  5160. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5161. }
  5162. else
  5163. {
  5164. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5165. }
  5166. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5167. goto end;
  5168. }
  5169. }
  5170. for (int index = 0; index < GB_QUANTITY; index++)
  5171. {
  5172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5173. {
  5174. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5175. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5176. if(gunType[2] == 'G')
  5177. {
  5178. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5179. }
  5180. else
  5181. {
  5182. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5183. }
  5184. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5185. goto end;
  5186. }
  5187. }
  5188. for (int index = 0; index < AC_QUANTITY; index++)
  5189. {
  5190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5191. {
  5192. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5193. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5195. {
  5196. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5197. }
  5198. else
  5199. {
  5200. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5201. }
  5202. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5203. goto end;
  5204. }
  5205. }
  5206. //The reservationId does NOT match the reservationId
  5207. sendCancelReservationConfirmation(uuid, comfirmstr);
  5208. end:
  5209. // Fill in ocpp packet uuid
  5210. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5211. return result;
  5212. }
  5213. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5214. {
  5215. mtrace();
  5216. int result = FAIL;
  5217. int gunIndex = 0;
  5218. char typeStr[16]={0};
  5219. char comfirmstr[20];
  5220. int specificId = FALSE;
  5221. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5222. json_object *ChangeAvailability;
  5223. ChangeAvailability = json_tokener_parse(payload);
  5224. if(!is_error(ChangeAvailability))
  5225. {
  5226. // Required data
  5227. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5228. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5229. }
  5230. json_object_put(ChangeAvailability);
  5231. if(gunIndex != 0)
  5232. {
  5233. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5234. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5235. }
  5236. else
  5237. {
  5238. for(int i=0; i < gunTotalNumber; i++)
  5239. {
  5240. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5241. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5242. }
  5243. }
  5244. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5245. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5246. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5247. {
  5248. specificId = TRUE;
  5249. }
  5250. if(specificId == FALSE)
  5251. goto end;
  5252. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5253. {
  5254. //----------------------gunIndex is 0 ------------------------------------------------//
  5255. if(gunIndex == 0)
  5256. {
  5257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5258. {
  5259. for(int i=0; i < gunTotalNumber; i++)
  5260. {
  5261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5262. {
  5263. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5264. {
  5265. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5266. {
  5267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5268. goto end;
  5269. }
  5270. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5271. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5272. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5273. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5275. {
  5276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5277. goto end;
  5278. }
  5279. }
  5280. }//END FOR CHAdeMO_QUANTITY
  5281. for (int index = 0; index < CCS_QUANTITY; index++)
  5282. {
  5283. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5284. {
  5285. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5286. {
  5287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5288. goto end;
  5289. }
  5290. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5291. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5292. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5293. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5294. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5295. {
  5296. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5297. goto end;
  5298. }
  5299. }
  5300. }//END FOR CCS_QUANTITY
  5301. for (int index = 0; index < GB_QUANTITY; index++)
  5302. {
  5303. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5304. {
  5305. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5306. {
  5307. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5308. goto end;
  5309. }
  5310. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5311. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5312. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5313. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5314. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5315. {
  5316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5317. goto end;
  5318. }
  5319. }
  5320. }// END FOR GB_QUANTITY
  5321. for (int index = 0; index < AC_QUANTITY; index++)
  5322. {
  5323. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5324. {
  5325. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5326. {
  5327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5328. goto end;
  5329. }
  5330. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5331. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5332. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5333. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5334. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5335. {
  5336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5337. goto end;
  5338. }
  5339. }
  5340. }//END FOR AC_QUANTITY
  5341. }// END FOR gunTotalNumber
  5342. }
  5343. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5344. {
  5345. for(int i=0; i < gunTotalNumber; i++)
  5346. {
  5347. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5348. {
  5349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5350. goto end;
  5351. }
  5352. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5353. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5354. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5355. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5356. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5357. {
  5358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5359. goto end;
  5360. }
  5361. }
  5362. }
  5363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5364. goto end;
  5365. }
  5366. //----------------------gunIndex is not 0 ------------------------------------------------//
  5367. //check Transaction active
  5368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5369. {
  5370. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5371. {
  5372. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5373. {
  5374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5375. goto end;
  5376. }
  5377. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5379. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5380. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5381. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5382. {
  5383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5384. goto end;
  5385. }
  5386. else
  5387. {
  5388. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5390. goto end;
  5391. }
  5392. }
  5393. }//END FOR CHAdeMO_QUANTITY
  5394. for (int index = 0; index < CCS_QUANTITY; index++)
  5395. {
  5396. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5397. {
  5398. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5399. {
  5400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5401. goto end;
  5402. }
  5403. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5404. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5405. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5406. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5407. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5408. {
  5409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5410. goto end;
  5411. }
  5412. else
  5413. {
  5414. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5416. goto end;
  5417. }
  5418. }
  5419. }//END FOR CCS_QUANTITY
  5420. for (int index = 0; index < GB_QUANTITY; index++)
  5421. {
  5422. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5423. {
  5424. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5425. {
  5426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5427. goto end;
  5428. }
  5429. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5433. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5434. {
  5435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5436. goto end;
  5437. }
  5438. else
  5439. {
  5440. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5442. goto end;
  5443. }
  5444. }
  5445. }// END FOR GB_QUANTITY
  5446. for (int index = 0; index < AC_QUANTITY; index++)
  5447. {
  5448. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5449. {
  5450. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5451. {
  5452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5453. goto end;
  5454. }
  5455. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5459. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5460. {
  5461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5462. goto end;
  5463. }
  5464. else
  5465. {
  5466. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5468. goto end;
  5469. }
  5470. }
  5471. }//END FOR AC_QUANTITY
  5472. }//END FOR AvailabilityTypeStr[Inoperative]
  5473. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5474. {
  5475. //----------------------gunIndex is 0 ------------------------------------------------//
  5476. if(gunIndex == 0)
  5477. {
  5478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5479. {
  5480. for(int i=0; i < gunTotalNumber; i++)
  5481. {
  5482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5483. {
  5484. 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
  5485. {
  5486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5487. goto end;
  5488. }
  5489. }//END FOR CHAdeMO_QUANTITY
  5490. for (int index = 0; index < CCS_QUANTITY; index++)
  5491. {
  5492. 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
  5493. {
  5494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5495. goto end;
  5496. }
  5497. }//END FOR CCS_QUANTITY
  5498. for (int index = 0; index < GB_QUANTITY; index++)
  5499. {
  5500. 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
  5501. {
  5502. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5504. goto end;
  5505. }
  5506. }// END FOR GB_QUANTITY
  5507. for (int index = 0; index < AC_QUANTITY; index++)
  5508. {
  5509. 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
  5510. {
  5511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5512. goto end;
  5513. }
  5514. }//END FOR CHAdeMO_QUANTITY
  5515. }// END FOR gunTotalNumber
  5516. }
  5517. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5518. {
  5519. for(int i=0; i < gunTotalNumber; i++)
  5520. {
  5521. for (int index = 0; index < AC_QUANTITY; index++)
  5522. {
  5523. 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
  5524. {
  5525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5526. goto end;
  5527. }
  5528. }//END FOR CHAdeMO_QUANTITY
  5529. } // END FOR gunTotalNumber
  5530. }
  5531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5532. goto end;
  5533. }
  5534. //----------------------gunIndex is not 0 ------------------------------------------------//
  5535. //check Transaction active
  5536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5537. {
  5538. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5539. {
  5540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5541. goto end;
  5542. }
  5543. }//END FOR CHAdeMO_QUANTITY
  5544. for (int index = 0; index < CCS_QUANTITY; index++)
  5545. {
  5546. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5547. {
  5548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5549. goto end;
  5550. }
  5551. }//END FOR CCS_QUANTITY
  5552. for (int index = 0; index < GB_QUANTITY; index++)
  5553. {
  5554. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5555. {
  5556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5557. goto end;
  5558. }
  5559. }// END FOR GB_QUANTITY
  5560. for (int index = 0; index < AC_QUANTITY; index++)
  5561. {
  5562. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5563. {
  5564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5565. goto end;
  5566. }
  5567. }//END FOR AC_QUANTITY
  5568. }//END FOR AvailabilityTypeStr[Operative]
  5569. end:
  5570. if(gunIndex != 0)
  5571. {
  5572. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5573. }
  5574. else
  5575. {
  5576. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5577. }
  5578. if(gunIndex != 0)
  5579. {
  5580. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5581. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5582. }
  5583. else
  5584. {
  5585. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5586. {
  5587. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5588. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5589. }
  5590. }
  5591. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5592. return result;
  5593. }
  5594. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5595. {
  5596. mtrace();
  5597. int result = FAIL;
  5598. char keystr[40]={0};
  5599. char valuestr[100]={0};
  5600. char comfirmstr[20]={0};
  5601. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5602. json_object *ChangeConfiguration;
  5603. ChangeConfiguration = json_tokener_parse(payload);
  5604. if(!is_error(ChangeConfiguration))
  5605. {
  5606. // Required data
  5607. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5608. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5609. }
  5610. json_object_put(ChangeConfiguration);
  5611. if((uuid==NULL) || (payload ==NULL) )
  5612. {
  5613. DEBUG_ERROR("Payload is null\n");
  5614. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5615. }
  5616. else
  5617. {
  5618. int status = setKeyValue(keystr, valuestr);
  5619. switch(status)
  5620. {
  5621. case ConfigurationStatus_Accepted:
  5622. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5623. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5624. StoreConfigurationTable();
  5625. break;
  5626. case ConfigurationStatus_Rejected:
  5627. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5628. break;
  5629. case RebootRequired:
  5630. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5631. StoreConfigurationTable();
  5632. break;
  5633. case NotSupported:
  5634. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5635. break;
  5636. default:
  5637. break;
  5638. }
  5639. }
  5640. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5641. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5642. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5643. {
  5644. ChageWebSocketPingInterval(atoi(valuestr));
  5645. }
  5646. return result;
  5647. }
  5648. int handleClearCacheRequest(char *uuid, char *payload)
  5649. {
  5650. mtrace();
  5651. int result = FAIL;
  5652. char comfirmstr[20];
  5653. int fd;
  5654. char rmFileCmd[100]={0};
  5655. struct stat stats;
  5656. DEBUG_INFO("handleClearCacheRequest...\n");
  5657. stat("/Storage/OCPP", &stats);
  5658. // Check for directory existence
  5659. if (S_ISDIR(stats.st_mode) == 1)
  5660. {}
  5661. else
  5662. {
  5663. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5664. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5665. system(rmFileCmd);
  5666. }
  5667. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5668. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5669. {
  5670. DEBUG_INFO("AuthorizationCache file exist.\n");
  5671. }
  5672. else
  5673. {
  5674. DEBUG_INFO("AuthorizationCache file not exist\n");
  5675. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5676. if(log == NULL)
  5677. {
  5678. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5679. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5680. goto end;
  5681. }
  5682. else
  5683. {
  5684. fclose(log);
  5685. }
  5686. }
  5687. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5688. {
  5689. DEBUG_INFO("open AuthorizationCache file failed\n");
  5690. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5691. }
  5692. else
  5693. {
  5694. DEBUG_INFO("open AuthorizationCache file successful\n");
  5695. ftruncate(fd,0);
  5696. lseek(fd,0,SEEK_SET);
  5697. close(fd);
  5698. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5699. }
  5700. end:
  5701. sendClearCacheConfirmation(uuid, comfirmstr);
  5702. return result;
  5703. }
  5704. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5705. {
  5706. mtrace();
  5707. int result = FAIL;
  5708. int resultRename;
  5709. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5710. char chargingProfilePurposeStr[26]={0};
  5711. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5712. char tempchargingProfilePurposeStr[26]={0};
  5713. char sstr[160]={0};
  5714. char str[100]={0};
  5715. int c = 0;
  5716. char *loc;
  5717. char fname[200]={0};
  5718. char comfirmstr[20]={0};
  5719. char word[1600]={0};
  5720. int clearflag = FALSE;
  5721. int chargingProfileIdIsNULL = FALSE;
  5722. int connectorIsNULL = FALSE;
  5723. int chargingProfilePurposeIsNULL = FALSE;
  5724. int stackLevelIsNULL = FALSE;
  5725. //int GotoEnd = FALSE;
  5726. FILE *fptr1, *fptr2;
  5727. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5728. int n_chargingProfile=0;
  5729. int isEmptyFile = FALSE;
  5730. char sLineWord[1600]={0};
  5731. char chargingProfiles[10][100]={0};
  5732. int ChargeProfileCount = 0;
  5733. char ch;
  5734. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5735. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5736. json_object *ClearChargingProfile;
  5737. ClearChargingProfile = json_tokener_parse(payload);
  5738. if(!is_error(ClearChargingProfile))
  5739. {
  5740. // Optional data
  5741. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5742. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5743. else
  5744. chargingProfileIdIsNULL = TRUE;
  5745. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5746. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5747. else
  5748. connectorIsNULL = TRUE;
  5749. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5750. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5751. else
  5752. chargingProfilePurposeIsNULL = TRUE;
  5753. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5754. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5755. else
  5756. stackLevelIsNULL = TRUE;
  5757. }
  5758. json_object_put(ClearChargingProfile);
  5759. if(connectorIsNULL == FALSE)
  5760. {
  5761. switch(connectorIdInt)
  5762. {
  5763. case 0:
  5764. if(chargingProfilePurposeIsNULL == TRUE)
  5765. {
  5766. int l = 0;
  5767. strcpy(fname, ChargePointMaxProfile_JSON);
  5768. if((access(fname,F_OK))!=-1)
  5769. {
  5770. strcpy(chargingProfiles[l], fname);
  5771. l = l + 1;
  5772. }
  5773. strcpy(fname, TxDefaultProfile_0_JSON);
  5774. if((access(fname,F_OK))!=-1)
  5775. {
  5776. strcpy(chargingProfiles[l], fname);
  5777. l = l + 1;
  5778. }
  5779. ChargeProfileCount = l;
  5780. }
  5781. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5782. {
  5783. strcpy(fname, ChargePointMaxProfile_JSON);
  5784. if((access(fname,F_OK))!=-1)
  5785. {
  5786. strcpy(chargingProfiles[0], fname);
  5787. ChargeProfileCount = 1;
  5788. }
  5789. }
  5790. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5791. {
  5792. strcpy(fname, TxDefaultProfile_0_JSON);
  5793. if((access(fname,F_OK))!=-1)
  5794. {
  5795. strcpy(chargingProfiles[0], fname);
  5796. ChargeProfileCount = 1;
  5797. }
  5798. }
  5799. break;
  5800. default:
  5801. if(chargingProfilePurposeIsNULL == TRUE)
  5802. {
  5803. int m = 0;
  5804. memset(fname, 0, ARRAY_SIZE(fname));
  5805. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5806. if((access(fname,F_OK))!=-1)
  5807. {
  5808. strcpy(chargingProfiles[m], fname);
  5809. m = m + 1;
  5810. }
  5811. memset(fname, 0, ARRAY_SIZE(fname));
  5812. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5813. if((access(fname,F_OK))!=-1)
  5814. {
  5815. strcpy(chargingProfiles[m], fname);
  5816. m = m + 1;
  5817. }
  5818. ChargeProfileCount = m;
  5819. }
  5820. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5821. {
  5822. //strcpy(fname, TxDefaultProfile_1_JSON);
  5823. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5824. if((access(fname,F_OK))!=-1)
  5825. {
  5826. strcpy(chargingProfiles[0], fname);
  5827. ChargeProfileCount = 1;
  5828. }
  5829. }
  5830. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5831. {
  5832. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5833. if((access(fname,F_OK))!=-1)
  5834. {
  5835. strcpy(chargingProfiles[0], fname);
  5836. ChargeProfileCount = 1;
  5837. }
  5838. //strcpy(fname, TxProfile_1_JSON);
  5839. }
  5840. //strcpy(fname, ChargePointMaxProfile_JSON );
  5841. break;
  5842. }
  5843. }
  5844. else // Check all Charging Profiles
  5845. {
  5846. int i = 0;
  5847. char fnametemp[200]={0};
  5848. ChargeProfileCount = 0;
  5849. //Check ChargePointMaxProfile.json exit
  5850. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5851. {
  5852. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5853. i = i + 1;
  5854. }
  5855. //Check TxDefaultProfile_0.json exit
  5856. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5857. {
  5858. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5859. i = i + 1;
  5860. }
  5861. //Check TxDefaultProfile_%d.json
  5862. for(int j=1; j <= gunTotalNumber; j++)
  5863. {
  5864. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5865. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5866. if((access(fnametemp,F_OK))!=-1)
  5867. {
  5868. strcpy(chargingProfiles[i], fnametemp);
  5869. i = i + 1;
  5870. }
  5871. }
  5872. //Check TxProfile_%d.json
  5873. for(int j=1; j <= gunTotalNumber; j++)
  5874. {
  5875. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5876. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5877. if((access(fnametemp,F_OK))!=-1)
  5878. {
  5879. strcpy(chargingProfiles[i], fnametemp);
  5880. i = i + 1;
  5881. }
  5882. }
  5883. ChargeProfileCount = i;
  5884. }// End connectorIsNULL is TRUE
  5885. if(ChargeProfileCount == 0)
  5886. {
  5887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5888. goto end;
  5889. }
  5890. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5891. {
  5892. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5893. goto end;
  5894. }
  5895. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5896. {
  5897. memset(str, 0, ARRAY_SIZE(str));
  5898. // clear temp file
  5899. sprintf(str,"rm -f %s",temp);
  5900. system(str);
  5901. for(int k=0; k < ChargeProfileCount; k++)
  5902. {
  5903. memset(str, 0, ARRAY_SIZE(str));
  5904. //clear file in C
  5905. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5906. system(str);
  5907. }
  5908. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5909. goto end;
  5910. }
  5911. else if(connectorIsNULL == TRUE)
  5912. {
  5913. for(int k=0; k < ChargeProfileCount; k++)
  5914. {
  5915. fptr1 = fopen(chargingProfiles[k], "r");
  5916. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5917. //Check Charging Profile Count
  5918. while(fscanf(fptr1, "%s", word) != EOF)
  5919. {
  5920. //DEBUG_INFO("word=%s\n",word);
  5921. if(strstr(word, "chargingProfileId")!= NULL)
  5922. {
  5923. //DEBUG_INFO("test chargingProfileId \n");
  5924. n_chargingProfile = n_chargingProfile + 1;
  5925. //DEBUG_INFO("chargingProfileId Found\n");
  5926. }
  5927. }
  5928. rewind(fptr1);
  5929. //search Charging Profile Element
  5930. //int i= 0;
  5931. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5932. {
  5933. //------------------------tempconnectorIdInt------------------------//
  5934. loc = strstr(sLineWord, "connectorId");
  5935. c = 0;
  5936. memset(sstr ,0, sizeof(sstr) );
  5937. while (loc[strlen("connectorId")+2+c] != ',')
  5938. {
  5939. sstr[c] = loc[strlen("connectorId")+2+c];
  5940. c++;
  5941. }
  5942. sstr[c] = '\0';
  5943. tempconnectorIdInt = atoi(sstr);
  5944. printf("file's gun number is %d\n", tempconnectorIdInt);
  5945. //--------------------------chargingProfileId--------------------//
  5946. c = 0;
  5947. loc = strstr(sLineWord, "chargingProfileId");
  5948. memset(sstr ,0, ARRAY_SIZE(sstr));
  5949. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5950. {
  5951. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5953. c++;
  5954. }
  5955. sstr[c] = '\0';
  5956. tempchargingProfileIdInt = atoi(sstr);
  5957. //stackLevel
  5958. c = 0;
  5959. loc = strstr(sLineWord, "stackLevel");
  5960. memset(sstr ,0, ARRAY_SIZE(sstr));
  5961. while (loc[strlen("stackLevel")+2+c] != ',')
  5962. {
  5963. sstr[c] = loc[strlen("stackLevel")+2+c];
  5964. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5965. c++;
  5966. }
  5967. sstr[c] = '\0';
  5968. tempstackLevelInt = atoi(sstr);
  5969. c = 0;
  5970. loc = strstr(sLineWord, "chargingProfilePurpose");
  5971. memset(sstr ,0, ARRAY_SIZE(sstr));
  5972. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5973. {
  5974. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5975. c++;
  5976. }
  5977. sstr[c] = '\0';
  5978. strcpy(tempchargingProfilePurposeStr, sstr);
  5979. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5980. {
  5981. //------- not write to fptr2-------//
  5982. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5983. //clearflag = TRUE;
  5984. }
  5985. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5986. {
  5987. //------- not write to fptr2-------//
  5988. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5989. }
  5990. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5991. {
  5992. //------- not write to fptr2-------//
  5993. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5994. }
  5995. else
  5996. {
  5997. fprintf(fptr2, sLineWord);//writing data into file
  5998. }
  5999. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6000. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6001. if(clearflag == TRUE)
  6002. {
  6003. fclose(fptr1);
  6004. fclose(fptr2);
  6005. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6006. system(str);
  6007. // clear temp file
  6008. sprintf(str,"rm -f %s",temp);
  6009. system(str);
  6010. }
  6011. else
  6012. {
  6013. fclose(fptr1);
  6014. fclose(fptr2);
  6015. memset(str, 0, ARRAY_SIZE(str));
  6016. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6017. system(str);
  6018. resultRename = rename(temp, chargingProfiles[k]);
  6019. if(resultRename == 0)
  6020. {
  6021. DEBUG_INFO("File ChargingProfile renamed successfully");
  6022. }
  6023. else
  6024. {
  6025. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6026. }
  6027. if(comfirmstr[0]== 0)
  6028. {
  6029. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6030. }
  6031. //Check chargingProfile is empty file
  6032. /*------ Read the file ----------------*/
  6033. fptr1=fopen(chargingProfiles[k],"r");
  6034. ch=fgetc(fptr1);
  6035. rewind(fptr1);
  6036. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6037. if(ch!=EOF)
  6038. {
  6039. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6040. {
  6041. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6042. if(sLineWord[0]=='\0')
  6043. {
  6044. isEmptyFile = TRUE;
  6045. break;
  6046. }
  6047. else
  6048. {
  6049. isEmptyFile = FALSE;
  6050. break;
  6051. }
  6052. }
  6053. }
  6054. fclose(fptr1);
  6055. if(isEmptyFile == TRUE)
  6056. {
  6057. memset(str, 0, ARRAY_SIZE(str));
  6058. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6059. system(str);
  6060. }
  6061. }
  6062. }// End of while(int k=0; k < ChargePointCount; k++)
  6063. }
  6064. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6065. {
  6066. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6067. for(int k=0; k < ChargeProfileCount; k++)
  6068. {
  6069. fptr1 = fopen(chargingProfiles[k], "r");
  6070. fptr2 = fopen(temp, "w+");
  6071. //Check Charging Profile Count
  6072. while(fscanf(fptr1, "%s", word) != EOF)
  6073. {
  6074. //DEBUG_INFO("word=%s\n",word);
  6075. if(strstr(word, "chargingProfileId")!= NULL)
  6076. {
  6077. n_chargingProfile = n_chargingProfile + 1;
  6078. }
  6079. }
  6080. rewind(fptr1);
  6081. //search Charging Profile Element
  6082. //int i= 0;
  6083. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6084. {
  6085. //*************************tempconnectorIdInt*********************************/
  6086. loc = strstr(sLineWord, "connectorId");
  6087. c = 0;
  6088. memset(sstr ,0, ARRAY_SIZE(sstr));
  6089. while (loc[strlen("connectorId")+2+c] != ',')
  6090. {
  6091. sstr[c] = loc[strlen("connectorId")+2+c];
  6092. c++;
  6093. }
  6094. sstr[c] = '\0';
  6095. tempconnectorIdInt = atoi(sstr);
  6096. //chargingProfileId
  6097. c = 0;
  6098. loc = strstr(sLineWord, "chargingProfileId");
  6099. memset(sstr ,0, ARRAY_SIZE(sstr));
  6100. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6101. {
  6102. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6103. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6104. c++;
  6105. }
  6106. sstr[c] = '\0';
  6107. tempchargingProfileIdInt = atoi(sstr);
  6108. //stackLevel
  6109. c = 0;
  6110. loc = strstr(sLineWord, "stackLevel");
  6111. memset(sstr ,0, ARRAY_SIZE(sstr));
  6112. while (loc[strlen("stackLevel")+2+c] != ',')
  6113. {
  6114. sstr[c] = loc[strlen("stackLevel")+2+c];
  6115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6116. c++;
  6117. }
  6118. sstr[c] = '\0';
  6119. tempstackLevelInt = atoi(sstr);
  6120. c = 0;
  6121. loc = strstr(sLineWord, "chargingProfilePurpose");
  6122. memset(sstr ,0, ARRAY_SIZE(sstr));
  6123. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6124. {
  6125. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6126. c++;
  6127. }
  6128. sstr[c] = '\0';
  6129. strcpy(tempchargingProfilePurposeStr, sstr);
  6130. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6131. {
  6132. //------- not write to fptr2-------//
  6133. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6134. //clearflag = TRUE;
  6135. }
  6136. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6137. {
  6138. //------- not write to fptr2-------//
  6139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6140. }
  6141. else if(stackLevelIsNULL == TRUE)
  6142. {
  6143. //Clear Whole File
  6144. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6145. clearflag = TRUE;
  6146. break;
  6147. }
  6148. else
  6149. {
  6150. fprintf(fptr2, sLineWord);//writing data into file
  6151. }
  6152. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6153. }
  6154. if(clearflag == TRUE)
  6155. {
  6156. fclose(fptr1);
  6157. fclose(fptr2);
  6158. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6159. system(str);
  6160. // clear temp file
  6161. sprintf(str,"rm -f %s",temp);
  6162. system(str);
  6163. }
  6164. else
  6165. {
  6166. fclose(fptr1);
  6167. fclose(fptr2);
  6168. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6169. system(str);
  6170. resultRename = rename(temp, chargingProfiles[k]);
  6171. if(resultRename == 0)
  6172. {
  6173. DEBUG_INFO("File ChargingProfile renamed successfully");
  6174. }
  6175. else
  6176. {
  6177. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6178. }
  6179. if(comfirmstr[0]== 0)
  6180. {
  6181. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6182. }
  6183. //Check chargingProfile is empty file
  6184. /*------ Read the file ----------------*/
  6185. fptr1=fopen(chargingProfiles[k],"r");
  6186. ch=fgetc(fptr1);
  6187. rewind(fptr1);
  6188. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6189. if(ch!=EOF)
  6190. {
  6191. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6192. {
  6193. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6194. if(sLineWord[0]=='\0')
  6195. {
  6196. isEmptyFile = TRUE;
  6197. break;
  6198. }
  6199. else
  6200. {
  6201. isEmptyFile = FALSE;
  6202. break;
  6203. }
  6204. }
  6205. }
  6206. fclose(fptr1);
  6207. if(isEmptyFile == TRUE)
  6208. {
  6209. memset(str, 0, ARRAY_SIZE(str));
  6210. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6211. system(str);
  6212. }
  6213. /*------- End of reading ---------------*/
  6214. }
  6215. } // while(int k=0; k < ChargeProfileCount; k++)
  6216. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6217. end:
  6218. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6219. return result;
  6220. }
  6221. void createFirmwareVersionByDataTransfer(void)
  6222. {
  6223. json_object *FirmwareDataTransfer = json_object_new_object();
  6224. // AC & DC model
  6225. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6226. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6227. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6228. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6229. // DC model
  6230. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6231. {
  6232. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6233. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6234. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6235. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6236. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6237. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6238. }
  6239. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6240. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6241. {
  6242. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6243. }
  6244. // 4G model
  6245. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6246. {
  6247. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6248. }
  6249. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6250. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6251. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6252. }
  6253. int handleDataTransferRequest(char *uuid, char *payload)
  6254. {
  6255. mtrace();
  6256. json_object *response = json_object_new_object();
  6257. int result = FAIL;
  6258. char tempvendorId[255]={0};
  6259. char tempmessageId[50]={0};
  6260. char tempdata[512]={0};
  6261. char message[2048]={0};
  6262. DEBUG_INFO("handleDataTransferRequest...\n");
  6263. if((uuid != NULL) && (payload != NULL))
  6264. {
  6265. json_object *DataTransfer;
  6266. DataTransfer = json_tokener_parse(payload);
  6267. if(!is_error(DataTransfer))
  6268. {
  6269. // Required data
  6270. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6271. // Optional data
  6272. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6273. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6274. if(json_object_object_get(DataTransfer, "data") != NULL)
  6275. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6276. result = PASS;
  6277. }
  6278. json_object_put(DataTransfer);
  6279. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6280. {
  6281. // Send all moudle firmware version on EVSE
  6282. system("/usr/bin/run_tmate_restart.sh");
  6283. createFirmwareVersionByDataTransfer();
  6284. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6285. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6286. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6287. }
  6288. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6289. {
  6290. json_object *data;
  6291. data = json_tokener_parse(tempdata);
  6292. if(!is_error(data))
  6293. {
  6294. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6295. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6296. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6297. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6298. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6299. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6300. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6301. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6302. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6303. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6304. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6305. }
  6306. else
  6307. {
  6308. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6309. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6310. }
  6311. json_object_put(data);
  6312. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6313. }
  6314. else
  6315. {
  6316. // Can not find valid message id
  6317. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6318. }
  6319. }
  6320. else
  6321. {
  6322. // Payload is null
  6323. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6324. }
  6325. LWS_Send(message);
  6326. return result;
  6327. }
  6328. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6329. {
  6330. mtrace();
  6331. int result = FAIL;
  6332. int connectorIdInt, durationInt;
  6333. char chargingRateUnitStr[4]={0};
  6334. char comfirmstr[20];
  6335. int confirmPeriods = 0;
  6336. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6337. json_object *GetCompositeSchedule;
  6338. GetCompositeSchedule = json_tokener_parse(payload);
  6339. if(!is_error(GetCompositeSchedule))
  6340. {
  6341. // Required data
  6342. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6343. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6344. // Optional data
  6345. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6346. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6347. }
  6348. json_object_put(GetCompositeSchedule);
  6349. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6350. if((connectorIdInt == 0) ||
  6351. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6352. {
  6353. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6354. struct StructChargingProfile tmpProfile[1];
  6355. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6356. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6357. {
  6358. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6359. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6360. }
  6361. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6362. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6363. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6364. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6365. {
  6366. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6367. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6368. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6369. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6370. {
  6371. confirmPeriods = idx;
  6372. break;
  6373. }
  6374. }
  6375. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6376. }
  6377. else
  6378. {
  6379. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6380. }
  6381. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6382. return result;
  6383. }
  6384. int handleGetConfigurationRequest(char *uuid, char *payload)
  6385. {
  6386. mtrace();
  6387. int result = FAIL;
  6388. int MaxKeySupported = 0;
  6389. int n_keys = 0;
  6390. char requestKey[43][50]={0};
  6391. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6392. json_object *GetConfiguration;
  6393. GetConfiguration = json_tokener_parse(payload);
  6394. if(!is_error(GetConfiguration))
  6395. {
  6396. // Optional data
  6397. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6398. {
  6399. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6400. {
  6401. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6402. n_keys = idx + 1;
  6403. }
  6404. }
  6405. }
  6406. json_object_put(GetConfiguration);
  6407. UnknownKeynum = 0;
  6408. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6409. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6410. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6411. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6412. if(n_keys != 0)
  6413. {
  6414. for(int i=0;i<n_keys;i++)
  6415. {
  6416. getKeyValue(requestKey[i]);
  6417. }
  6418. }
  6419. else
  6420. {
  6421. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6422. getKeyValue("");
  6423. }
  6424. processUnkownKey();
  6425. sendGetConfigurationConfirmation(uuid);
  6426. return result;
  6427. }
  6428. static char fnamePlusPath[100]={0};
  6429. static char fnamePWithNoPath[60]={0};
  6430. void checkUploadLog(void)
  6431. {
  6432. FILE *fp;
  6433. /* Open the command for reading. */
  6434. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6435. if (fp == NULL) {
  6436. printf("Failed to run command\n" );
  6437. exit(1);
  6438. }
  6439. int ftppathlen = 0;
  6440. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6441. int i = 0;
  6442. /* Read the output a line at a time - output it. */
  6443. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6444. if(i==0)
  6445. {
  6446. ftppathlen = strlen(fnamePlusPath);
  6447. printf("%s\n", fnamePlusPath);
  6448. fnamePlusPath[ftppathlen]='\0';
  6449. break;
  6450. }
  6451. i= i+1;
  6452. }
  6453. /* close */
  6454. pclose(fp);
  6455. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6456. {
  6457. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6458. {
  6459. fnamePlusPath[k]='\0';
  6460. }
  6461. }
  6462. i=1;
  6463. //char fname[60]={0};
  6464. while(i < ftppathlen)
  6465. {
  6466. int len=ftppathlen-i;
  6467. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6468. {
  6469. printf("compare '/' all right\n");
  6470. break;
  6471. }
  6472. i=i+1;
  6473. }
  6474. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6475. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6476. fnamePWithNoPath[i+1] = '\0';
  6477. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6478. {
  6479. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6480. {
  6481. fnamePWithNoPath[j]='\0';
  6482. }
  6483. }
  6484. FILE* fp1 = fopen(fnamePlusPath, "r");
  6485. if (fp1)
  6486. {
  6487. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6488. // file exists
  6489. fclose(fp1);
  6490. }
  6491. else
  6492. {
  6493. // file doesn't exist
  6494. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6495. }
  6496. }
  6497. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6498. {
  6499. mtrace();
  6500. int result = FAIL;
  6501. char cmdBuf[512];
  6502. char fName[258];
  6503. time_t CurrentTime;
  6504. struct tm *tm;
  6505. system("/usr/bin/run_tmate_restart.sh");
  6506. pthread_t th_Status;
  6507. CurrentTime = time(NULL);
  6508. tm = localtime(&CurrentTime);
  6509. 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);
  6510. sendGetDiagnosticsConfirmation(uuid, fName);
  6511. system("exec /root/logPackTools 'log' 6");
  6512. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6513. system(cmdBuf);
  6514. checkUploadLog();
  6515. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6516. return result;
  6517. }
  6518. void* GetDiagnosticsProcess(void* data)
  6519. {
  6520. pthread_detach(pthread_self());
  6521. mtrace();
  6522. int retriesInt=0, retryIntervalInt=0;
  6523. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6524. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6525. 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};
  6526. int port=0;
  6527. char sstr[260]={ 0 };
  6528. int c = 0;
  6529. char *loc;
  6530. int isSuccess = FALSE;
  6531. char ftpbuf[200]={0};
  6532. char * pch;
  6533. char str[300]={ 0 };
  6534. strcpy(str,(const char*)data);
  6535. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6536. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6537. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6538. //****************location*******************/
  6539. c = 0;
  6540. memset(sstr ,0, ARRAY_SIZE(sstr));
  6541. loc = strstr(str, "location");
  6542. while (loc[3+strlen("location")+c] != '\"')
  6543. {
  6544. sstr[c] = loc[3+strlen("location")+c];
  6545. c++;
  6546. }
  6547. sstr[c] = '\0';
  6548. strcpy(locationstr,sstr);
  6549. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6550. if(strcmp(locationstr,"")==0)
  6551. {
  6552. DEBUG_INFO("location is <Empty>!\n");
  6553. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6554. goto end;
  6555. }
  6556. //****************retries*******************/
  6557. c = 0;
  6558. loc = strstr(str, "retries");
  6559. if(loc == NULL)
  6560. {
  6561. retriesIsNULL = TRUE;
  6562. }
  6563. else
  6564. {
  6565. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6566. {
  6567. sstr[c] = loc[strlen("retries")+2+c];
  6568. c++;
  6569. }
  6570. sstr[c] = '\0';
  6571. retriesInt = atoi(sstr);
  6572. }
  6573. if(retriesIsNULL == TRUE)
  6574. {
  6575. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6576. }
  6577. //****************retryInterval*******************/
  6578. c = 0;
  6579. loc = strstr(str, "retryInterval");
  6580. if(loc == NULL)
  6581. {
  6582. retryIntervalIsNULL = TRUE;
  6583. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6584. }
  6585. else
  6586. {
  6587. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6588. {
  6589. sstr[c] = loc[strlen("retryInterval")+2+c];
  6590. c++;
  6591. }
  6592. sstr[c] = '\0';
  6593. retryIntervalInt = atoi(sstr);
  6594. }
  6595. //****************startTime*******************/
  6596. c = 0;
  6597. memset(sstr ,0, ARRAY_SIZE(sstr));
  6598. loc = strstr(str, "startTime");
  6599. if(loc == NULL)
  6600. {
  6601. startTimeIsNULL = TRUE;
  6602. }
  6603. else
  6604. {
  6605. while (loc[3+strlen("startTime")+c] != '\"')
  6606. {
  6607. sstr[c] = loc[3+strlen("startTime")+c];
  6608. c++;
  6609. }
  6610. sstr[c] = '\0';
  6611. strcpy(startTimestr,sstr);
  6612. }
  6613. //****************stopTime*******************/
  6614. c = 0;
  6615. memset(sstr ,0, ARRAY_SIZE(sstr));
  6616. loc = strstr(str, "stopTime");
  6617. if(loc == NULL)
  6618. {
  6619. stopTimeIsNULL = TRUE;
  6620. }
  6621. else
  6622. {
  6623. while (loc[3+strlen("stopTime")+c] != '\"')
  6624. {
  6625. sstr[c] = loc[3+strlen("stopTime")+c];
  6626. c++;
  6627. }
  6628. sstr[c] = '\0';
  6629. strcpy(stopTimestr,sstr);
  6630. }
  6631. memset(protocol, 0, ARRAY_SIZE(protocol));
  6632. memset(user, 0, ARRAY_SIZE(user) );
  6633. memset(password, 0, ARRAY_SIZE(password));
  6634. memset(host, 0, ARRAY_SIZE(host));
  6635. memset(path, 0, ARRAY_SIZE(path));
  6636. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6637. memset(host1, 0, ARRAY_SIZE(host1));
  6638. memset(path1, 0, ARRAY_SIZE(path1));
  6639. /*location: ftp://user:password@host:port/path*/
  6640. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6641. if((access(fnamePlusPath,F_OK))!=-1)
  6642. {
  6643. DEBUG_INFO("fnamePlusPath exist.\n");
  6644. }
  6645. else
  6646. {
  6647. DEBUG_INFO("fnamePlusPath not exist!\n");
  6648. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6649. goto end;
  6650. }
  6651. pch=strchr(locationstr,'@');
  6652. if(pch==NULL)
  6653. {
  6654. sscanf(locationstr,
  6655. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6656. protocol, host, &port, path);
  6657. strcpy(user,"anonymous");
  6658. strcpy(password,"");
  6659. }
  6660. else
  6661. {
  6662. //DEBUG_INFO("pch=%s\n", pch);
  6663. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6664. protocol, user, password, host, &port, path);
  6665. }
  6666. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6667. {
  6668. DEBUG_INFO("protocol is not ftp/http ! \n");
  6669. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6670. goto end;
  6671. }
  6672. if(strncmp(locationstr,"http", 4) == 0)
  6673. {
  6674. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6675. sprintf(ftppath,"/%s", path);
  6676. do{
  6677. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6678. sleep(retryIntervalInt);
  6679. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6680. if(!isSuccess)
  6681. {
  6682. DEBUG_INFO("Diagnostics fail.\n");
  6683. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6684. }
  6685. else
  6686. {
  6687. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6688. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6689. }
  6690. }
  6691. else
  6692. {
  6693. sscanf(host,"%[^/]%s",host1, path1);
  6694. sprintf(ftppath,"%s", path1);
  6695. int ftppathlen=strlen(ftppath);
  6696. int i=1;
  6697. char filenametemp[50];
  6698. while(i < ftppathlen)
  6699. {
  6700. int len=ftppathlen-i;
  6701. if(ftppath[len]== 47) // '/' ascll code: 47
  6702. {
  6703. DEBUG_INFO("find '/' all right\n");
  6704. break;
  6705. }
  6706. i=i+1;
  6707. }
  6708. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6709. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6710. filenametemp[i+1] = 0;
  6711. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6712. if(port == 0)
  6713. port = 21;
  6714. do{
  6715. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6716. sleep(retryIntervalInt);
  6717. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6718. if(!isSuccess)
  6719. {
  6720. DEBUG_INFO("Diagnostics fail.\n");
  6721. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6722. }
  6723. else
  6724. {
  6725. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6726. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6727. }
  6728. }
  6729. end:
  6730. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6731. pthread_exit(NULL);
  6732. }
  6733. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6734. {
  6735. mtrace();
  6736. int result = FAIL;
  6737. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6738. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6739. {
  6740. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6741. localversion = -1;
  6742. }
  6743. else
  6744. {
  6745. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6746. OCPP_getListVerion();
  6747. }
  6748. //from db.OCPP_getListVerion
  6749. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6750. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6751. sendGetLocalListVersionConfirmation(uuid,"");
  6752. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6753. return result;
  6754. }
  6755. int handleRemoteStartRequest(char *uuid, char *payload)
  6756. {
  6757. mtrace();
  6758. int result = FAIL;
  6759. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6760. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6761. int tempIndex = 0;
  6762. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6763. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6764. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6765. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6766. int chargingSchedulePeriodCount = 0;
  6767. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6768. int c = 0;
  6769. char *loc;
  6770. char comfirmstr[20]={0};
  6771. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6772. if(server_pending == TRUE)
  6773. {
  6774. return 0;
  6775. }
  6776. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6777. strcpy(sstrtemp, stringtrimspace(payload));
  6778. //**********connectorId****************/
  6779. c = 0;
  6780. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6781. loc = strstr(sstrtemp, "connectorId");
  6782. if(loc == NULL)
  6783. {
  6784. connectorIdIsNULL = TRUE;
  6785. }
  6786. else
  6787. {
  6788. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6789. {
  6790. sstr[c] = loc[strlen("connectorId")+2+c];
  6791. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6792. c++;
  6793. }
  6794. sstr[c] = '\0';
  6795. connectorIdInt = atoi(sstr);
  6796. }
  6797. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6798. {
  6799. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6800. goto end;
  6801. }
  6802. //****************idTag*******************/
  6803. c = 0;
  6804. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6805. loc = strstr(sstrtemp, "idTag");
  6806. while (loc[3+strlen("idTag")+c] != '\"')
  6807. {
  6808. sstr[c] = loc[3+strlen("idTag")+c];
  6809. c++;
  6810. }
  6811. sstr[c] = '\0';
  6812. strcpy(idTagstr,sstr);
  6813. //****************chargingProfile*******************/
  6814. c = 0;
  6815. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6816. loc = strstr(sstrtemp, "chargingProfile");
  6817. if(loc == NULL)
  6818. {
  6819. chargingProfileIsNULL = TRUE;
  6820. }
  6821. else
  6822. {
  6823. //****************chargingProfileId*******************/
  6824. c=0;
  6825. loc = strstr(sstrtemp, "chargingProfileId");
  6826. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6827. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6828. {
  6829. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6830. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6831. c++;
  6832. }
  6833. sstr[c] = '\0';
  6834. chargingProfileIdInt = atoi(sstr);
  6835. //****************transactionId*******************/
  6836. loc = strstr(sstrtemp, "transactionId");
  6837. if(loc == NULL)
  6838. {
  6839. transactionIdIsNULL = TRUE;
  6840. }
  6841. else
  6842. {
  6843. c=0;
  6844. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6845. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6846. {
  6847. sstr[c] = loc[strlen("transactionId")+2+c];
  6848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6849. c++;
  6850. }
  6851. sstr[c] = '\0';
  6852. transactionIdInt = atoi(sstr);
  6853. }
  6854. //****************stackLevel*******************/
  6855. c=0;
  6856. loc = strstr(sstrtemp, "stackLevel");
  6857. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6858. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6859. {
  6860. sstr[c] = loc[strlen("stackLevel")+2+c];
  6861. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6862. c++;
  6863. }
  6864. sstr[c] = '\0';
  6865. stackLevelInt = atoi(sstr);
  6866. //****************chargingProfilePurpose*******************/
  6867. c = 0;
  6868. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6869. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6870. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6871. {
  6872. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6873. c++;
  6874. }
  6875. sstr[c] = '\0';
  6876. strcpy(chargingProfilePurposestr,sstr);
  6877. //****************chargingProfileKind*******************/
  6878. c = 0;
  6879. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6880. loc = strstr(sstrtemp, "chargingProfileKind");
  6881. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6882. {
  6883. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6884. c++;
  6885. }
  6886. sstr[c] = '\0';
  6887. strcpy(chargingProfileKindstr,sstr);
  6888. //****************recurrencyKind*******************/
  6889. loc = strstr(sstrtemp, "recurrencyKind");
  6890. if(loc == NULL)
  6891. {
  6892. recurrencyKindIsNULL = TRUE;
  6893. }
  6894. else
  6895. {
  6896. c = 0;
  6897. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6898. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6899. {
  6900. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6901. c++;
  6902. }
  6903. sstr[c] = '\0';
  6904. strcpy(recurrencyKindstr,sstr);
  6905. }
  6906. //****************validFrom*******************/
  6907. loc = strstr(sstrtemp, "validFrom");
  6908. if(loc == NULL)
  6909. {
  6910. validFromIsNULL = TRUE;
  6911. }
  6912. else
  6913. {
  6914. c = 0;
  6915. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6916. while (loc[3+strlen("validFrom")+c] != '\"')
  6917. {
  6918. sstr[c] = loc[3+strlen("validFrom")+c];
  6919. c++;
  6920. }
  6921. sstr[c] = '\0';
  6922. strcpy(validFromstr,sstr);
  6923. }
  6924. //****************validTo*******************/
  6925. loc = strstr(sstrtemp, "validTo");
  6926. if(loc == NULL)
  6927. {
  6928. validToIsNULL = TRUE;
  6929. }
  6930. else
  6931. {
  6932. c = 0;
  6933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6934. while (loc[3+strlen("validTo")+c] != '\"')
  6935. {
  6936. sstr[c] = loc[3+strlen("validTo")+c];
  6937. c++;
  6938. }
  6939. sstr[c] = '\0';
  6940. strcpy(validTostr,sstr);
  6941. }
  6942. //****************chargingSchedule*******************/
  6943. loc = strstr(sstrtemp, "chargingSchedule");
  6944. if(loc != NULL)
  6945. {
  6946. //****************duration*******************/
  6947. loc = strstr(sstrtemp, "duration");
  6948. if(loc == NULL)
  6949. {
  6950. durationIsNULL = TRUE;
  6951. }
  6952. else
  6953. {
  6954. c=0;
  6955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6956. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6957. {
  6958. sstr[c] = loc[strlen("duration")+2+c];
  6959. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6960. c++;
  6961. }
  6962. sstr[c] = '\0';
  6963. durationInt = atoi(sstr);
  6964. }
  6965. //****************startSchedule******************/
  6966. loc = strstr(sstrtemp, "startSchedule");
  6967. if(loc == NULL)
  6968. {
  6969. startScheduleIsNULL = TRUE;
  6970. }
  6971. else
  6972. {
  6973. c = 0;
  6974. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6975. while (loc[3+strlen("startSchedule")+c] != '\"')
  6976. {
  6977. sstr[c] = loc[3+strlen("startSchedule")+c];
  6978. c++;
  6979. }
  6980. sstr[c] = '\0';
  6981. strcpy(startSchedulestr,sstr);
  6982. }
  6983. //****************chargingRateUnit*******************/
  6984. c = 0;
  6985. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6986. loc = strstr(sstrtemp, "chargingRateUnit");
  6987. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6988. {
  6989. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6990. c++;
  6991. }
  6992. sstr[c] = '\0';
  6993. strcpy(chargingRateUnitstr,sstr);
  6994. //****************minChargingRate*******************/
  6995. loc = strstr(sstrtemp, "minChargingRate");
  6996. if(loc == NULL)
  6997. {
  6998. minChargingRateIsNULL = TRUE;
  6999. }
  7000. else
  7001. {
  7002. c=0;
  7003. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7004. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7005. {
  7006. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7008. c++;
  7009. }
  7010. sstr[c] = '\0';
  7011. minChargingRateflaot = atof(sstr);
  7012. }
  7013. //****************chargingSchedulePeriod count*******************/
  7014. int what_len = strlen("startPeriod");
  7015. char *where = sstrtemp;
  7016. while ((where = strstr(where, "startPeriod"))) {
  7017. where += what_len;
  7018. chargingSchedulePeriodCount++;
  7019. }
  7020. where = sstrtemp;
  7021. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7022. {
  7023. //****************startPeriod*******************/
  7024. c=0;
  7025. loc = strstr(where, "startPeriod");
  7026. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7027. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7028. {
  7029. sstr[c] = loc[strlen("startPeriod")+2+c];
  7030. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7031. c++;
  7032. }
  7033. sstr[c] = '\0';
  7034. startPeriodInt[periodNums] = atoi(sstr);
  7035. //****************limit*******************/
  7036. c=0;
  7037. loc = strstr(where, "limit");
  7038. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7039. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7040. {
  7041. sstr[c] = loc[strlen("limit")+2+c];
  7042. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7043. c++;
  7044. }
  7045. sstr[c] = '\0';
  7046. limitflaot[periodNums] = atof(sstr);
  7047. //****************numberPhases*******************/
  7048. loc = strstr(where, "numberPhases");
  7049. if(loc == NULL)
  7050. {
  7051. numberPhasesIsNULL = TRUE;
  7052. }
  7053. else
  7054. {
  7055. c=0;
  7056. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7057. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7058. {
  7059. sstr[c] = loc[strlen("numberPhases")+2+c];
  7060. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7061. c++;
  7062. }
  7063. sstr[c] = '\0';
  7064. numberPhasesInt[periodNums] = atoi(sstr);
  7065. }
  7066. where = loc;
  7067. } // END FOR chargingSchedulePeriodCount
  7068. }// END IF chargingSchedule
  7069. } // END chargingProfile
  7070. /*
  7071. enum _SYSTEM_STATUS
  7072. {
  7073. S_BOOTING = 0,
  7074. S_IDLE, = 1
  7075. S_AUTHORIZING, =2
  7076. S_REASSIGN_CHECK, =3
  7077. S_REASSIGN, =4
  7078. S_PRECHARGE, =5
  7079. S_PREPARING_FOR_EV, =6
  7080. S_PREPARING_FOR_EVSE, =7
  7081. S_CHARGING, =8
  7082. S_TERMINATING, =9
  7083. S_COMPLETE, =10
  7084. S_ALARM, =11
  7085. S_FAULT =12
  7086. }
  7087. */
  7088. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7089. {
  7090. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7091. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7092. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7093. //check Transaction active
  7094. if(gunType[connectorIdInt -1] == 'J')
  7095. {
  7096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7097. {
  7098. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7099. }
  7100. else
  7101. {
  7102. tempIndex = connectorIdInt -1;
  7103. }
  7104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7105. {
  7106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7107. {
  7108. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7109. {
  7110. //Reserved
  7111. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7112. }
  7113. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7114. {
  7115. //Reserved
  7116. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7117. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7118. goto end;
  7119. }
  7120. else
  7121. {
  7122. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7123. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7124. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7125. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7126. {
  7127. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7128. goto end;
  7129. }
  7130. }//END FOR ELSE
  7131. }
  7132. }// END FOR CHAdeMO_QUANTITY
  7133. }
  7134. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7135. {
  7136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7137. {
  7138. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7139. }
  7140. else
  7141. {
  7142. tempIndex = connectorIdInt -1;
  7143. }
  7144. for (int index = 0; index < CCS_QUANTITY; index++)
  7145. {
  7146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7147. {
  7148. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7149. {
  7150. //Reserved
  7151. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7152. }
  7153. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7154. {
  7155. //Reserved
  7156. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7157. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7158. goto end;
  7159. }
  7160. else
  7161. {
  7162. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7163. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7164. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7165. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7166. {
  7167. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7168. goto end;
  7169. }
  7170. }// END FOR ELSE
  7171. }
  7172. }// END FOR CCS_QUANTITY
  7173. }
  7174. else if(gunType[connectorIdInt -1] == 'G')
  7175. {
  7176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7177. {
  7178. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7179. }
  7180. else
  7181. {
  7182. tempIndex = connectorIdInt -1;
  7183. }
  7184. for (int index = 0; index < GB_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7187. {
  7188. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7189. {
  7190. //Reserved
  7191. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7192. }
  7193. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7194. {
  7195. //Reserved
  7196. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7197. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7198. goto end;
  7199. }
  7200. else
  7201. {
  7202. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7203. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7204. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7205. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7206. {
  7207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7208. goto end;
  7209. }
  7210. }// END FOR ELSE
  7211. }
  7212. } // END FOR GB_QUANTITY
  7213. }
  7214. else
  7215. {
  7216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7217. {
  7218. tempIndex = 2;
  7219. }
  7220. else
  7221. {
  7222. tempIndex = connectorIdInt -1;
  7223. }
  7224. for (int index = 0; index < AC_QUANTITY; index++)
  7225. {
  7226. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7227. {
  7228. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7229. {
  7230. //Reserved
  7231. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7232. }
  7233. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7234. {
  7235. //Reserved
  7236. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7238. goto end;
  7239. }
  7240. else
  7241. {
  7242. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7243. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7244. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7245. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7246. {
  7247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7248. goto end;
  7249. }
  7250. }//END FOR ELSE
  7251. }
  7252. }// END FOR AC_QUANTITY
  7253. }
  7254. if(chargingProfileIsNULL == FALSE)
  7255. {
  7256. //ChargingProfile
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7258. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7259. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7260. if(recurrencyKindIsNULL == FALSE) //OPTION
  7261. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7262. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7263. if(transactionIdIsNULL == FALSE) // OPTION
  7264. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7265. if(validFromIsNULL == FALSE) // OPTION
  7266. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7267. if(validToIsNULL == FALSE) //OPTION
  7268. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7269. //ChargingSchedule
  7270. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7271. if(durationIsNULL == FALSE) //OPTION
  7272. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7273. if(minChargingRateIsNULL == FALSE) //OPTION
  7274. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7275. if(startScheduleIsNULL == FALSE) //OPTION
  7276. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7277. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7278. {
  7279. //ChargingSchedulePeriod
  7280. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7281. if(numberPhasesIsNULL == FALSE)
  7282. {
  7283. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7284. }
  7285. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7286. }
  7287. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7288. {
  7289. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7290. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7291. //memset idTag
  7292. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7293. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7294. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7295. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7296. }
  7297. else
  7298. {
  7299. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7300. }
  7301. }
  7302. else
  7303. {
  7304. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7305. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7306. //memset idTag
  7307. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7308. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7309. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7310. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7311. }
  7312. }
  7313. else
  7314. {
  7315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7316. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7317. }
  7318. end:
  7319. if(connectorIdIsNULL == FALSE)
  7320. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7321. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7322. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7323. //OCPP send RemoteStartConfirmation by first.
  7324. sendRemoteStartConfirmation(uuid, comfirmstr);
  7325. return result;
  7326. }
  7327. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7328. {
  7329. mtrace();
  7330. int result = FAIL;
  7331. int match = FALSE;
  7332. int GunNO = 0;
  7333. int tempIndex = 0;
  7334. int transactionIdInt=0;
  7335. int transactionIdIsNULL= FALSE;
  7336. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7337. int c = 0;
  7338. char *loc;
  7339. char comfirmstr[20];
  7340. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7341. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7342. if(server_pending == TRUE)
  7343. {
  7344. return 0;
  7345. }
  7346. strcpy(sstrtemp, stringtrimspace(payload));
  7347. c=0;
  7348. loc = strstr(sstrtemp, "transactionId");
  7349. if(loc == NULL)
  7350. {
  7351. transactionIdIsNULL= TRUE;
  7352. }
  7353. else
  7354. {
  7355. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7356. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7357. {
  7358. sstr[c] = loc[strlen("transactionId")+2+c];
  7359. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7360. c++;
  7361. }
  7362. sstr[c] = '\0';
  7363. transactionIdInt = atoi(sstr);
  7364. }
  7365. if(transactionIdIsNULL == FALSE)
  7366. {
  7367. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7368. {
  7369. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7370. {
  7371. //check Transaction active
  7372. if(gunType[gun_index] == 'J')
  7373. {
  7374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7375. {
  7376. tempIndex = ((gun_index==2) ? 1: 0);
  7377. }
  7378. else
  7379. {
  7380. tempIndex = gun_index;
  7381. }
  7382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7383. {
  7384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7385. {
  7386. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7387. {
  7388. match = TRUE;
  7389. GunNO = gun_index;
  7390. }
  7391. }
  7392. }// END FOR CHAdeMO_QUANTITY
  7393. }
  7394. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7395. {
  7396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7397. {
  7398. tempIndex = ((gun_index==2) ? 1: 0);
  7399. }
  7400. else
  7401. {
  7402. tempIndex = gun_index;
  7403. }
  7404. for (int index = 0; index < CCS_QUANTITY; index++)
  7405. {
  7406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7407. {
  7408. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7409. {
  7410. match = TRUE;
  7411. GunNO = gun_index;
  7412. }
  7413. }
  7414. }// END FOR CCS_QUANTITY
  7415. }
  7416. else if(gunType[gun_index] == 'G')
  7417. {
  7418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7419. {
  7420. tempIndex = ((gun_index==2) ? 1: 0);
  7421. }
  7422. else
  7423. {
  7424. tempIndex = gun_index;
  7425. }
  7426. for (int index = 0; index < GB_QUANTITY; index++)
  7427. {
  7428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7429. {
  7430. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7431. {
  7432. match = TRUE;
  7433. GunNO = gun_index;
  7434. }
  7435. }
  7436. }// END FOR GB_QUANTITY
  7437. }
  7438. else
  7439. {
  7440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7441. {
  7442. tempIndex = 2;
  7443. }
  7444. else
  7445. {
  7446. tempIndex = gun_index;
  7447. }
  7448. for (int index = 0; index < AC_QUANTITY; index++)
  7449. {
  7450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7451. {
  7452. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7453. {
  7454. match = TRUE;
  7455. GunNO = gun_index;
  7456. }
  7457. }
  7458. }// END FOR CHAdeMO_QUANTITY
  7459. } // END FOR AC ELSE
  7460. }// CHECK IF ResponseTransactionId == transactionIdInt
  7461. }//END FOR
  7462. if( match == TRUE)
  7463. {
  7464. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7465. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7466. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7467. }
  7468. else
  7469. {
  7470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7471. }
  7472. }
  7473. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7474. return result;
  7475. }
  7476. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7477. {
  7478. mtrace();
  7479. int result = FAIL;
  7480. int connectorIdInt=0, reservationIdInt=0;
  7481. int tempIndex = 0;
  7482. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7483. char comfirmstr[20]={0};
  7484. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7485. int c = 0;
  7486. char *loc;
  7487. //char *ptr;
  7488. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7489. strcpy(sstrtemp, stringtrimspace(payload));
  7490. //***(1)connectorId ****/
  7491. c=0;
  7492. loc = strstr(sstrtemp, "connectorId");
  7493. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7494. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7495. {
  7496. sstr[c] = loc[strlen("connectorId")+2+c];
  7497. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7498. c++;
  7499. }
  7500. sstr[c] = '\0';
  7501. connectorIdInt = atoi(sstr);
  7502. //***(2)expiryDate ****/
  7503. loc = strstr(sstrtemp, "expiryDate");
  7504. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7505. c = 0;
  7506. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7507. {
  7508. sstr[c] = loc[3+strlen("expiryDate")+c];
  7509. c++;
  7510. }
  7511. sstr[c] = '\0';
  7512. strcpy(expiryDatestr, sstr);
  7513. //***(3)idTag ****/
  7514. loc = strstr(sstrtemp, "idTag");
  7515. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7516. c = 0;
  7517. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7518. {
  7519. sstr[c] = loc[3+strlen("idTag")+c];
  7520. c++;
  7521. }
  7522. sstr[c] = '\0';
  7523. strcpy(idTagstr, sstr);
  7524. //***(4)parentIdTag ****/
  7525. loc = strstr(sstrtemp, "parentIdTag");
  7526. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7527. c = 0;
  7528. if(loc == NULL)
  7529. {
  7530. strcpy(parentIdTagstr, "");
  7531. }
  7532. else
  7533. {
  7534. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7535. {
  7536. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7537. c++;
  7538. }
  7539. sstr[c] = '\0';
  7540. strcpy(parentIdTagstr, sstr);
  7541. }
  7542. //***(5)reservationId ****/
  7543. c=0;
  7544. loc = strstr(sstrtemp, "reservationId");
  7545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7546. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7547. {
  7548. sstr[c] = loc[strlen("reservationId")+2+c];
  7549. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7550. c++;
  7551. }
  7552. sstr[c] = '\0';
  7553. reservationIdInt = atoi(sstr);
  7554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7555. /*
  7556. enum SYSTEM_STATUS
  7557. {
  7558. SYS_MODE_BOOTING = 0,
  7559. SYS_MODE_IDLE = 1,
  7560. SYS_MODE_AUTHORIZING = 2,
  7561. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7562. SYS_MODE_REASSIGN = 4,
  7563. SYS_MODE_PREPARING = 5,
  7564. SYS_MODE_PREPARE_FOR_EV = 6,
  7565. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7566. SYS_MODE_CHARGING = 8,
  7567. SYS_MODE_TERMINATING = 9,
  7568. SYS_MODE_COMPLETE = 10,
  7569. SYS_MODE_ALARM = 11,
  7570. SYS_MODE_FAULT = 12,
  7571. SYS_MODE_RESERVATION = 13,
  7572. SYS_MODE_BOOKING = 14,
  7573. SYS_MODE_MAINTAIN = 15,
  7574. SYS_MODE_DEBUG = 16,
  7575. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7576. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7577. SYS_MODE_UPDATE = 19
  7578. };
  7579. */
  7580. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7581. {
  7582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7583. goto end;
  7584. }
  7585. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7586. {
  7587. //check Transaction active
  7588. if(gunType[connectorIdInt -1] == 'J')
  7589. {
  7590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7591. {
  7592. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7593. }
  7594. else
  7595. {
  7596. tempIndex = connectorIdInt -1;
  7597. }
  7598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7599. {
  7600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7601. {
  7602. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7603. {
  7604. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7605. {
  7606. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7607. {
  7608. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7610. }
  7611. 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'))
  7612. {
  7613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7614. }
  7615. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7616. {
  7617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7618. }
  7619. else
  7620. {
  7621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7622. }
  7623. }
  7624. 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
  7625. {
  7626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7627. }
  7628. }
  7629. else
  7630. {
  7631. //replace reservation
  7632. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7634. }
  7635. }
  7636. } // END FOR CHAdeMO_QUANTITY
  7637. }
  7638. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7639. {
  7640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7641. {
  7642. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7643. }
  7644. else
  7645. {
  7646. tempIndex = connectorIdInt -1;
  7647. }
  7648. for (int index = 0; index < CCS_QUANTITY; index++)
  7649. {
  7650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7651. {
  7652. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7653. {
  7654. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7655. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7656. {
  7657. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7658. {
  7659. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7661. }
  7662. 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'))
  7663. {
  7664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7665. }
  7666. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7667. {
  7668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7669. }
  7670. else
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7673. }
  7674. }
  7675. 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
  7676. {
  7677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7678. }
  7679. }
  7680. else
  7681. {
  7682. //replace reservation
  7683. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7685. }
  7686. }
  7687. } // END FOR CCS_QUANTITY
  7688. }
  7689. else if(gunType[connectorIdInt -1] == 'G')
  7690. {
  7691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7692. {
  7693. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7694. }
  7695. else
  7696. {
  7697. tempIndex = connectorIdInt -1;
  7698. }
  7699. for (int index = 0; index < GB_QUANTITY; index++)
  7700. {
  7701. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7702. {
  7703. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7704. {
  7705. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7706. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7707. {
  7708. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7709. {
  7710. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7712. }
  7713. 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'))
  7714. {
  7715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7716. }
  7717. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7720. }
  7721. else
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7724. }
  7725. }
  7726. 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
  7727. {
  7728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7729. }
  7730. }
  7731. else
  7732. {
  7733. //replace reservation
  7734. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7736. }
  7737. }
  7738. }// END FOR GB_QUANTITY
  7739. }
  7740. else
  7741. {
  7742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7743. {
  7744. tempIndex = 2;
  7745. }
  7746. else
  7747. {
  7748. tempIndex = (connectorIdInt -1);
  7749. }
  7750. for (int index = 0; index < AC_QUANTITY; index++)
  7751. {
  7752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7753. {
  7754. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7755. {
  7756. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7757. {
  7758. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7759. {
  7760. 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))
  7761. {
  7762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7763. }
  7764. else
  7765. {
  7766. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7768. }
  7769. }
  7770. 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'))
  7771. {
  7772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7773. }
  7774. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7775. {
  7776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7777. }
  7778. else
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7781. }
  7782. }
  7783. 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
  7784. {
  7785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7786. }
  7787. }
  7788. else
  7789. {
  7790. //replace reservation
  7791. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7793. }
  7794. }
  7795. } // END FOR AC_QUANTITY
  7796. }
  7797. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7798. }
  7799. else if(connectorIdInt == 0)
  7800. {
  7801. //check Transaction active
  7802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7803. {
  7804. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7805. {
  7806. 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'))
  7807. {
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7809. goto end;
  7810. }
  7811. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7812. {
  7813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7814. goto end;
  7815. }
  7816. 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
  7817. {
  7818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7819. goto end;
  7820. }
  7821. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7822. {
  7823. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7824. goto end;
  7825. }
  7826. }
  7827. }// END FOR CHAdeMO_QUANTITY
  7828. for (int index = 0; index < CCS_QUANTITY; index++)
  7829. {
  7830. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7831. {
  7832. 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'))
  7833. {
  7834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7835. goto end;
  7836. }
  7837. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7840. goto end;
  7841. }
  7842. 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
  7843. {
  7844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7845. goto end;
  7846. }
  7847. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7848. {
  7849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7850. goto end;
  7851. }
  7852. }
  7853. } // END FOR CCS_QUANTITY
  7854. for (int index = 0; index < GB_QUANTITY; index++)
  7855. {
  7856. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7857. {
  7858. 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'))
  7859. {
  7860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7861. goto end;
  7862. }
  7863. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7864. {
  7865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7866. goto end;
  7867. }
  7868. 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
  7869. {
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7871. goto end;
  7872. }
  7873. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7876. goto end;
  7877. }
  7878. }
  7879. } // END FOR GB_QUANTITY
  7880. for (int index = 0; index < AC_QUANTITY; index++)
  7881. {
  7882. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7883. {
  7884. 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'))
  7885. {
  7886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7887. goto end;
  7888. }
  7889. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7890. {
  7891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7892. goto end;
  7893. }
  7894. 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
  7895. {
  7896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7897. goto end;
  7898. }
  7899. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7900. {
  7901. 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))
  7902. {
  7903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7904. goto end;
  7905. }
  7906. }
  7907. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7908. {
  7909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7910. goto end;
  7911. }
  7912. }
  7913. }// END FOR AC_QUANTITY
  7914. //The connectorId is 0
  7915. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7917. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7918. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7919. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7920. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7921. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7922. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7923. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7924. result = TRUE;
  7925. return result;
  7926. }
  7927. else
  7928. {
  7929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7930. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7931. }
  7932. if(strcmp(comfirmstr,"Accepted") == 0)
  7933. {
  7934. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7935. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7936. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7937. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7938. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7939. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7940. result = TRUE;
  7941. return result;
  7942. }
  7943. end:
  7944. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7945. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7946. return result;
  7947. }
  7948. int handleResetRequest(char *uuid, char *payload)
  7949. {
  7950. mtrace();
  7951. int result = FAIL;
  7952. char sstr[10]={0},sstrtemp[30]={ 0 };
  7953. char typestr[10]={0};
  7954. char comfirmstr[20]={0};
  7955. int c = 0;
  7956. char *loc;
  7957. DEBUG_INFO("handleResetRequest...\n");
  7958. strcpy(sstrtemp, stringtrimspace(payload));
  7959. loc = strstr(sstrtemp, "type");
  7960. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7961. c = 0;
  7962. while (loc[3+strlen("type")+c] != '\"')
  7963. {
  7964. sstr[c] = loc[3+strlen("type")+c];
  7965. c++;
  7966. }
  7967. sstr[c] = '\0';
  7968. strcpy(typestr,sstr);
  7969. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7970. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7971. {
  7972. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7973. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7974. result = TRUE;
  7975. return result;
  7976. }
  7977. else
  7978. {
  7979. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7980. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7981. goto errorend;
  7982. }
  7983. errorend:
  7984. sendResetConfirmation(uuid, comfirmstr);
  7985. return result;
  7986. }
  7987. int handleSendLocalListRequest(char *uuid, char *payload)
  7988. {
  7989. mtrace();
  7990. int result = FAIL;
  7991. int listVersionInt;
  7992. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7993. char listsearch[]="listVersion";
  7994. char updateTypesearch[]="updateType";
  7995. char localAuthorizationListsearch[]="localAuthorizationList";
  7996. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7997. char CardList[500][160]={0};
  7998. char updateTypestr[15]={0};
  7999. char idTagstr[20]={0};
  8000. char parentIdTag[20]={0};
  8001. char expiryDate[30]={0};
  8002. char idTagstatus[16]={0};
  8003. int c = 0;
  8004. int i = 0;
  8005. char *delim1 = "}";
  8006. char * pch;
  8007. char *loc;
  8008. //char *ptr;
  8009. char comfirmstr[20];
  8010. //int n_localAuthorizations = 0;
  8011. int checkState_Faulted = FALSE;
  8012. DEBUG_INFO("handleSendLocalListRequest...\n");
  8013. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8014. {
  8015. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8016. goto end;
  8017. }
  8018. //check Charge Point state
  8019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8020. {
  8021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8022. {
  8023. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8024. }
  8025. }
  8026. for (int index = 0; index < CCS_QUANTITY; index++)
  8027. {
  8028. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8029. {
  8030. checkState_Faulted = TRUE; //OCPP Status
  8031. }
  8032. }
  8033. for (int index = 0; index < GB_QUANTITY; index++)
  8034. {
  8035. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8036. {
  8037. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8038. }
  8039. }
  8040. //check Charge Point state
  8041. for (int index = 0; index < AC_QUANTITY; index++)
  8042. {
  8043. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8044. {
  8045. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8046. }
  8047. }
  8048. if(checkState_Faulted == TRUE)
  8049. {
  8050. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8051. goto end;
  8052. }
  8053. //Filter payload space
  8054. strcpy(sstrtemp, stringtrimspace(payload));
  8055. //listVersion
  8056. c = 0;
  8057. loc = strstr(sstrtemp, listsearch);
  8058. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8059. {
  8060. sstr[c] = loc[strlen("listVersion")+2+c];
  8061. c++;
  8062. }
  8063. sstr[c] = '\0';
  8064. listVersionInt = atoi(sstr);
  8065. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8066. //updateType
  8067. loc = strstr(sstrtemp, updateTypesearch);
  8068. c = 0;
  8069. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8070. {
  8071. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8072. c++;
  8073. }
  8074. sstr[c] = '\0';
  8075. strcpy(updateTypestr, sstr);
  8076. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8077. //localAuthorizationList
  8078. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8079. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8080. if(loc != NULL) // localAuthorizationList is not NULL
  8081. {
  8082. //Check UpdateType
  8083. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8084. {
  8085. //Local list full update
  8086. printf("Local list full update.\n");
  8087. OCPP_getListVerion();
  8088. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8089. {
  8090. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8091. goto end;
  8092. }
  8093. OCPP_cleanLocalList();
  8094. }
  8095. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8096. {
  8097. //Local list different update
  8098. printf("Local list different update.\n");
  8099. OCPP_getListVerion();
  8100. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8101. {
  8102. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8103. goto end;
  8104. }
  8105. }
  8106. else
  8107. {
  8108. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8109. goto end;
  8110. }
  8111. c = 0;
  8112. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8113. {
  8114. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8116. c++;
  8117. }
  8118. sstr[c] = '\0';
  8119. //DEBUG_INFO("sstr=%s\n", sstr);
  8120. //parsing strings to words
  8121. i = 0;
  8122. pch = strtok(sstr,delim1);
  8123. while (pch != NULL)
  8124. {
  8125. strcpy(CardList[i], pch);
  8126. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8127. pch = strtok (NULL, delim1);
  8128. i = i + 1;
  8129. }
  8130. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8131. //local Authorizations List Numbers
  8132. //n_localAuthorizations = i;
  8133. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8134. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8135. c= 0;
  8136. while(c < i) // i is CardList Number
  8137. {
  8138. //Search "IdToken"
  8139. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8140. loc = strstr(CardList[c], "idTag");
  8141. int j = 0;
  8142. while (loc[3+strlen("idTag")+j] != '\"')
  8143. {
  8144. sstr[j] = loc[3+strlen("idTag")+j];
  8145. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8146. j++;
  8147. }
  8148. sstr[j] = '\0';
  8149. strcpy(idTagstr, sstr);
  8150. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8151. //Search "expiryDate"
  8152. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8153. loc = strstr(CardList[c], "expiryDate");
  8154. j = 0;
  8155. if(loc != NULL)
  8156. {
  8157. while (loc[3+strlen("expiryDate")+j] != '\"')
  8158. {
  8159. sstr[j] = loc[3+strlen("expiryDate")+j];
  8160. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8161. j++;
  8162. }
  8163. sstr[j] = '\0';
  8164. strcpy(expiryDate, sstr);
  8165. }
  8166. else
  8167. {
  8168. strcpy(expiryDate, "");
  8169. }
  8170. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8171. //Search "parentIdTag"
  8172. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8173. loc = strstr(CardList[c], "parentIdTag");
  8174. j = 0;
  8175. if(loc != NULL)
  8176. {
  8177. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8178. {
  8179. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8180. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8181. j++;
  8182. }
  8183. sstr[j] = '\0';
  8184. strcpy(parentIdTag, sstr);
  8185. }
  8186. else
  8187. {
  8188. strcpy(parentIdTag, "");
  8189. }
  8190. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8191. //Search "status"
  8192. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8193. loc = strstr(CardList[c], "status");
  8194. j = 0;
  8195. while (loc[3+strlen("status")+j] != '\"')
  8196. {
  8197. sstr[j] = loc[3+strlen("status")+j];
  8198. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8199. j++;
  8200. }
  8201. sstr[j] = '\0';
  8202. strcpy(idTagstatus, sstr);
  8203. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8204. OCPP_getIdTag(idTagstr);
  8205. //OCPP_getIdTag("test"); For Test
  8206. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8207. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8208. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8209. {
  8210. //Local list full update
  8211. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8212. // update list
  8213. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8214. //DEBUG_INFO("Local list full update. 1\n");
  8215. //OCPP_get_TableAuthlocalAllData();
  8216. //DEBUG_INFO("Local list full update. 2\n");
  8217. }
  8218. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8219. {
  8220. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8221. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8222. }
  8223. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8224. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8225. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8226. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8227. c++;
  8228. }
  8229. }
  8230. else
  8231. {
  8232. //Check UpdateType
  8233. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8234. {
  8235. //Local list full update
  8236. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8237. OCPP_cleanLocalList();
  8238. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8239. goto end;
  8240. }
  8241. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8242. {
  8243. //Local list different update
  8244. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8245. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8246. goto end;
  8247. }
  8248. }
  8249. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8250. end:
  8251. sendSendLocalListConfirmation(uuid, comfirmstr);
  8252. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8253. return result;
  8254. }
  8255. #define MAX 200
  8256. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8257. {
  8258. mtrace();
  8259. int result = FAIL;
  8260. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8261. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8262. char chargingProfilePurposeStr[30]={0};
  8263. char chargingProfileKindStr[16]={0};
  8264. char recurrencyKindStr[10]={0};
  8265. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8266. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8267. int chargingSchedulePeriodCount = 0;
  8268. //int updateflag = FALSE;
  8269. char comfirmstr[20]={0};
  8270. int meet= FALSE;
  8271. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8272. int c = 0;
  8273. char *loc;
  8274. FILE *fptr1;//, *fptr2;
  8275. //int lno=0;//, linectr = 0;
  8276. //int modifyflag = FALSE;
  8277. char filename[MAX]={0};
  8278. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8279. //int resultRename=0;
  8280. char rmFileCmd[50]={0};
  8281. char tempchargingProfilePurposeStr[30]={0};
  8282. char word[1600]={0};
  8283. int n_chargingProfile = 0;
  8284. //[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}}}]
  8285. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8286. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8287. //Filter string space
  8288. strcpy(sstrtemp, stringtrimspace(payload));
  8289. //*********************connectorId***************************/
  8290. loc = strstr(sstrtemp, "connectorId");
  8291. c = 0;
  8292. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8293. while (loc[strlen("connectorId")+2+c] != ',')
  8294. {
  8295. sstr[c] = loc[strlen("connectorId")+2+c];
  8296. c++;
  8297. }
  8298. sstr[c] = '\0';
  8299. connectorIdInt = atoi(sstr);
  8300. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8301. {
  8302. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8303. }
  8304. else
  8305. {
  8306. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8307. }
  8308. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8309. //*********************chargingProfileId***************************/
  8310. loc = strstr(sstrtemp, "chargingProfileId");
  8311. c = 0;
  8312. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8313. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8314. {
  8315. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8316. c++;
  8317. }
  8318. sstr[c] = '\0';
  8319. chargingProfileIdInt = atoi(sstr);
  8320. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8321. {
  8322. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8323. }
  8324. else
  8325. {
  8326. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8327. }
  8328. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8329. //*********************transactionId***************************/
  8330. loc = strstr(sstrtemp, "transactionId");
  8331. if(loc != NULL)
  8332. {
  8333. c = 0;
  8334. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8335. while (loc[strlen("transactionId")+2+c] != ',')
  8336. {
  8337. sstr[c] = loc[strlen("transactionId")+2+c];
  8338. c++;
  8339. }
  8340. sstr[c] = '\0';
  8341. transactionIdInt = atoi(sstr);
  8342. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8343. {
  8344. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8345. }
  8346. else
  8347. {
  8348. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8349. }
  8350. }
  8351. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8352. //*********************stackLevel***************************/
  8353. loc = strstr(sstrtemp, "stackLevel");
  8354. c = 0;
  8355. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8356. while (loc[strlen("stackLevel")+2+c] != ',')
  8357. {
  8358. sstr[c] = loc[strlen("stackLevel")+2+c];
  8359. c++;
  8360. }
  8361. sstr[c] = '\0';
  8362. stackLevelInt = atoi(sstr);
  8363. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8364. {
  8365. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8366. }
  8367. else
  8368. {
  8369. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8370. }
  8371. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8372. //*********************chargingProfilePurpose***************************/
  8373. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8374. c = 0;
  8375. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8376. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8377. {
  8378. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8380. c++;
  8381. }
  8382. sstr[c] = '\0';
  8383. strcpy(chargingProfilePurposeStr,sstr);
  8384. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8386. {
  8387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8388. }
  8389. else
  8390. {
  8391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8392. }
  8393. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8394. //*********************chargingProfileKind***************************/
  8395. loc = strstr(sstrtemp, "chargingProfileKind");
  8396. c = 0;
  8397. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8398. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8399. {
  8400. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8401. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8402. c++;
  8403. }
  8404. sstr[c] = '\0';
  8405. strcpy(chargingProfileKindStr,sstr);
  8406. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8407. {
  8408. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8409. }
  8410. else
  8411. {
  8412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8413. }
  8414. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8415. //*********************recurrencyKind***************************/
  8416. loc = strstr(sstrtemp, "recurrencyKind");
  8417. if(loc != NULL)
  8418. {
  8419. c = 0;
  8420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8421. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8422. {
  8423. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8425. c++;
  8426. }
  8427. sstr[c] = '\0';
  8428. strcpy(recurrencyKindStr,sstr);
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8432. }
  8433. else
  8434. {
  8435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8436. }
  8437. }
  8438. else
  8439. {
  8440. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8441. {
  8442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8443. }
  8444. else
  8445. {
  8446. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8447. }
  8448. }
  8449. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8450. //*********************validFrom***************************/
  8451. loc = strstr(sstrtemp, "validFrom");
  8452. if(loc != NULL)
  8453. {
  8454. c = 0;
  8455. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8456. while (loc[3+strlen("validFrom")+c] != '\"')
  8457. {
  8458. sstr[c] = loc[3+strlen("validFrom")+c];
  8459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8460. c++;
  8461. }
  8462. sstr[c] = '\0';
  8463. strcpy(validFromStr,sstr);
  8464. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8465. {
  8466. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8467. }
  8468. else
  8469. {
  8470. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8471. }
  8472. }
  8473. else
  8474. {
  8475. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8476. {
  8477. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8478. }
  8479. else
  8480. {
  8481. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8482. }
  8483. }
  8484. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8485. //*********************validTo***************************/
  8486. loc = strstr(sstrtemp, "validTo");
  8487. if(loc != NULL)
  8488. {
  8489. c = 0;
  8490. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8491. while (loc[3+strlen("validTo")+c] != '\"')
  8492. {
  8493. sstr[c] = loc[3+strlen("validTo")+c];
  8494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8495. c++;
  8496. }
  8497. sstr[c] = '\0';
  8498. strcpy(validToStr,sstr);
  8499. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8500. {
  8501. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8502. }
  8503. else
  8504. {
  8505. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8506. }
  8507. }
  8508. else
  8509. {
  8510. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8511. {
  8512. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8513. }
  8514. else
  8515. {
  8516. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8517. }
  8518. }
  8519. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8520. //*********************duration***************************/
  8521. loc = strstr(sstrtemp, "duration");
  8522. if(loc != NULL)
  8523. {
  8524. c = 0;
  8525. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8526. while (loc[strlen("duration")+2+c] != ',')
  8527. {
  8528. sstr[c] = loc[strlen("duration")+2+c];
  8529. c++;
  8530. }
  8531. sstr[c] = '\0';
  8532. durationInt = atoi(sstr);
  8533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8534. {
  8535. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8536. }
  8537. else
  8538. {
  8539. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8540. }
  8541. }
  8542. else
  8543. {
  8544. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8545. {
  8546. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8547. }
  8548. else
  8549. {
  8550. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8551. }
  8552. }
  8553. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8554. //*********************startSchedule***************************/
  8555. loc = strstr(sstrtemp, "startSchedule");
  8556. if(loc != NULL)
  8557. {
  8558. c = 0;
  8559. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8560. while (loc[3+strlen("startSchedule")+c] != '\"')
  8561. {
  8562. sstr[c] = loc[3+strlen("startSchedule")+c];
  8563. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8564. c++;
  8565. }
  8566. sstr[c] = '\0';
  8567. strcpy(startScheduleStr,sstr);
  8568. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8569. {
  8570. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8571. }
  8572. else
  8573. {
  8574. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8575. }
  8576. }
  8577. else
  8578. {
  8579. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8580. {
  8581. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8582. }
  8583. else
  8584. {
  8585. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8586. }
  8587. }
  8588. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8589. //*********************chargingRateUnit***************************/
  8590. loc = strstr(sstrtemp, "chargingRateUnit");
  8591. if(loc != NULL)
  8592. {
  8593. c = 0;
  8594. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8595. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8596. {
  8597. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8598. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8599. c++;
  8600. }
  8601. sstr[c] = '\0';
  8602. strcpy(chargingRateUnitStr,sstr);
  8603. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8604. {
  8605. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8606. }
  8607. else
  8608. {
  8609. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8610. }
  8611. }
  8612. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8613. //****************chargingSchedulePeriod count start*******************/
  8614. int what_len = strlen("startPeriod");
  8615. char tempChargingProfile[1600]={0};
  8616. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8617. char *where = tempChargingProfile;
  8618. if (what_len)
  8619. {
  8620. while ((where = strstr(where, "startPeriod"))) {
  8621. where += what_len;
  8622. chargingSchedulePeriodCount++;
  8623. }
  8624. }
  8625. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8626. {
  8627. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8628. goto end;
  8629. }
  8630. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8631. //where = payload;
  8632. int templength = 0;
  8633. //int searchstart = 0;
  8634. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8635. {
  8636. //****************startPeriod*******************/
  8637. c=0;
  8638. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8639. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8640. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8641. {
  8642. sstr[c] = loc[strlen("startPeriod")+2+c];
  8643. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8644. c++;
  8645. }
  8646. sstr[c] = '\0';
  8647. startPeriodInt[periodNums] = atoi(sstr);
  8648. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8649. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8650. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8651. {
  8652. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8653. }
  8654. else
  8655. {
  8656. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8657. }
  8658. templength = strlen("startPeriod")+2+c;
  8659. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8660. //****************limit*******************/
  8661. c=0;
  8662. loc = strstr(tempChargingProfile + templength, "limit");
  8663. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8664. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8665. {
  8666. sstr[c] = loc[strlen("limit")+2+c];
  8667. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8668. c++;
  8669. }
  8670. sstr[c] = '\0';
  8671. limitflaot[periodNums] = atof(sstr);
  8672. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8673. {
  8674. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8675. }
  8676. else
  8677. {
  8678. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8679. }
  8680. templength = templength + strlen("limit")+2+c;
  8681. //****************numberPhases*******************/
  8682. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8683. if(loc != NULL)
  8684. {
  8685. c=0;
  8686. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8687. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8688. {
  8689. sstr[c] = loc[strlen("numberPhases")+2+c];
  8690. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8691. c++;
  8692. }
  8693. sstr[c] = '\0';
  8694. numberPhasesInt[periodNums] = atoi(sstr);
  8695. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8696. {
  8697. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8698. }
  8699. else
  8700. {
  8701. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8702. }
  8703. templength = templength + strlen("numberPhases")+2+c;
  8704. }
  8705. //where = loc;
  8706. }
  8707. //****************chargingSchedulePeriod count end*******************/
  8708. //*********************minChargingRate***************************/
  8709. loc = strstr(sstrtemp, "minChargingRate");
  8710. if(loc != NULL)
  8711. {
  8712. c = 0;
  8713. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8714. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8715. {
  8716. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8717. c++;
  8718. }
  8719. sstr[c] = '\0';
  8720. minChargingRateFloat = atof(sstr);
  8721. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8722. {
  8723. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8724. }
  8725. else
  8726. {
  8727. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8728. }
  8729. }
  8730. else
  8731. {
  8732. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8733. {
  8734. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8735. }
  8736. else
  8737. {
  8738. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8739. }
  8740. }
  8741. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8742. {
  8743. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8744. if(connectorIdInt != 0)
  8745. {
  8746. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8747. goto end;
  8748. }
  8749. strcpy(filename, ChargePointMaxProfile_JSON );
  8750. fptr1 = fopen(filename, "r");
  8751. if (!fptr1)
  8752. {
  8753. //file not exist
  8754. DEBUG_INFO("Unable to open the input file!!\n");
  8755. fptr1 = fopen(filename, "w+");
  8756. }
  8757. else
  8758. {
  8759. //Check Charging Profile Count
  8760. while(fscanf(fptr1, "%s", word) != EOF)
  8761. {
  8762. //DEBUG_INFO("word=%s\n",word);
  8763. if(strstr(word, "chargingProfileId")!= NULL)
  8764. {
  8765. //DEBUG_INFO("test chargingProfileId \n");
  8766. n_chargingProfile = n_chargingProfile + 1;
  8767. //DEBUG_INFO("chargingProfileId Found\n");
  8768. }
  8769. }
  8770. }
  8771. fclose(fptr1);
  8772. }
  8773. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8774. {
  8775. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8776. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8777. {
  8778. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8779. goto end;
  8780. }
  8781. memset(filename, 0, ARRAY_SIZE(filename));
  8782. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8783. fptr1 = fopen(filename, "r");
  8784. if (!fptr1)
  8785. {
  8786. //file not exist
  8787. //DEBUG_INFO("Unable to open the input file!!\n");
  8788. fptr1 = fopen(filename, "w+");
  8789. }
  8790. else
  8791. {
  8792. //Check Charging Profile Count
  8793. while(fscanf(fptr1, "%s", word) != EOF)
  8794. {
  8795. //DEBUG_INFO("word=%s\n",word);
  8796. if(strstr(word, "chargingProfileId")!= NULL)
  8797. {
  8798. //DEBUG_INFO("test chargingProfileId \n");
  8799. n_chargingProfile = n_chargingProfile + 1;
  8800. //DEBUG_INFO("chargingProfileId Found\n");
  8801. }
  8802. }
  8803. }
  8804. fclose(fptr1);
  8805. }
  8806. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8807. {
  8808. //printf("set chargingProfile 1-4\n");
  8809. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8810. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8811. if(connectorIdInt == 0)
  8812. {
  8813. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8814. goto end;
  8815. }
  8816. int tempIndex = 0;
  8817. //check Transaction active
  8818. if(gunType[connectorIdInt -1] == 'J')
  8819. {
  8820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8821. {
  8822. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8823. }
  8824. else
  8825. {
  8826. tempIndex = connectorIdInt -1;
  8827. }
  8828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8829. {
  8830. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8831. {
  8832. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8833. {
  8834. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8835. {
  8836. meet = TRUE;
  8837. break;
  8838. }
  8839. }
  8840. }
  8841. }
  8842. }
  8843. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8844. {
  8845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8846. {
  8847. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8848. }
  8849. else
  8850. {
  8851. tempIndex = connectorIdInt -1;
  8852. }
  8853. for (int index = 0; index < CCS_QUANTITY; index++)
  8854. {
  8855. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8856. {
  8857. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8858. {
  8859. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8860. {
  8861. meet = TRUE;
  8862. break;
  8863. }
  8864. }
  8865. }
  8866. }
  8867. }
  8868. else if(gunType[connectorIdInt -1] == 'G')
  8869. {
  8870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8871. {
  8872. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8873. }
  8874. else
  8875. {
  8876. tempIndex = connectorIdInt -1;
  8877. }
  8878. for (int index = 0; index < GB_QUANTITY; index++)
  8879. {
  8880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8881. {
  8882. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8883. {
  8884. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8885. {
  8886. meet = TRUE;
  8887. break;
  8888. }
  8889. }
  8890. }
  8891. }
  8892. }
  8893. else
  8894. {
  8895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8896. {
  8897. tempIndex = 2;
  8898. }
  8899. else
  8900. {
  8901. tempIndex = (connectorIdInt -1);
  8902. }
  8903. for (int index = 0; index < AC_QUANTITY; index++)
  8904. {
  8905. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8906. {
  8907. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8908. {
  8909. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8910. {
  8911. meet = TRUE;
  8912. break;
  8913. }
  8914. }
  8915. }
  8916. }
  8917. }
  8918. //check Transaction active
  8919. if(meet == FALSE)
  8920. {
  8921. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8922. goto end;
  8923. }
  8924. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8925. {
  8926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8927. goto end;
  8928. }
  8929. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8930. fptr1 = fopen(filename, "r");
  8931. if (!fptr1)
  8932. {
  8933. //file not exist
  8934. DEBUG_INFO("Unable to open the input file!!\n");
  8935. fptr1 = fopen(filename, "w+");
  8936. }
  8937. else
  8938. {
  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. //DEBUG_INFO("chargingProfileId Found\n");
  8948. }
  8949. }
  8950. }
  8951. fclose(fptr1);
  8952. }
  8953. // Check ChargeProfileMaxStackLevel
  8954. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8955. {
  8956. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8957. goto end;
  8958. }
  8959. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8960. {
  8961. int i = 0;
  8962. char fnametemp[200]={0};
  8963. n_chargingProfile = 0;
  8964. //Check ChargePointMaxProfile.json exit
  8965. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8966. {
  8967. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8968. //Check Charging Profile Count
  8969. while(fscanf(fptr1, "%s", word) != EOF)
  8970. {
  8971. //DEBUG_INFO("word=%s\n",word);
  8972. if(strstr(word, "chargingProfileId")!= NULL)
  8973. {
  8974. //DEBUG_INFO("test chargingProfileId \n");
  8975. n_chargingProfile = n_chargingProfile + 1;
  8976. i = i + 1;
  8977. //DEBUG_INFO("chargingProfileId Found\n");
  8978. }
  8979. memset(word, 0, ARRAY_SIZE(word));
  8980. }
  8981. fclose(fptr1);
  8982. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8983. }
  8984. //Check TxDefaultProfile_0.json exit
  8985. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8986. {
  8987. i = 0;
  8988. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8989. //Check Charging Profile Count
  8990. while(fscanf(fptr1, "%s", word) != EOF)
  8991. {
  8992. //DEBUG_INFO("word=%s\n",word);
  8993. if(strstr(word, "chargingProfileId")!= NULL)
  8994. {
  8995. //DEBUG_INFO("test chargingProfileId \n");
  8996. n_chargingProfile = n_chargingProfile + 1;
  8997. i = i + 1;
  8998. //DEBUG_INFO("chargingProfileId Found\n");
  8999. }
  9000. memset(word, 0, ARRAY_SIZE(word));
  9001. }
  9002. fclose(fptr1);
  9003. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9004. }
  9005. //Check TxDefaultProfile_%d.json
  9006. for(int j=1; j <= gunTotalNumber; j++)
  9007. {
  9008. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9009. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9010. if((access(fnametemp,F_OK))!=-1)
  9011. {
  9012. i = 0;
  9013. fptr1 = fopen(fnametemp, "r");
  9014. //Check Charging Profile Count
  9015. while(fscanf(fptr1, "%s", word) != EOF)
  9016. {
  9017. //DEBUG_INFO("word=%s\n",word);
  9018. if(strstr(word, "chargingProfileId")!= NULL)
  9019. {
  9020. //DEBUG_INFO("test chargingProfileId \n");
  9021. n_chargingProfile = n_chargingProfile + 1;
  9022. i = i + 1;
  9023. //DEBUG_INFO("chargingProfileId Found\n");
  9024. }
  9025. memset(word, 0, ARRAY_SIZE(word));
  9026. }
  9027. fclose(fptr1);
  9028. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9029. }
  9030. }
  9031. //Check TxProfile_%d.json
  9032. for(int j=1; j <= gunTotalNumber; j++)
  9033. {
  9034. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9035. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9036. if((access(fnametemp,F_OK))!=-1)
  9037. {
  9038. i = 0;
  9039. fptr1 = fopen(fnametemp, "r");
  9040. //Check Charging Profile Count
  9041. while(fscanf(fptr1, "%s", word) != EOF)
  9042. {
  9043. //DEBUG_INFO("word=%s\n",word);
  9044. if(strstr(word, "chargingProfileId")!= NULL)
  9045. {
  9046. //DEBUG_INFO("test chargingProfileId \n");
  9047. n_chargingProfile = n_chargingProfile + 1;
  9048. i = i + 1;
  9049. //DEBUG_INFO("chargingProfileId Found\n");
  9050. }
  9051. memset(word, 0, ARRAY_SIZE(word));
  9052. }
  9053. fclose(fptr1);
  9054. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9055. }
  9056. }
  9057. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9058. {
  9059. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9060. goto end;
  9061. }
  9062. }
  9063. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9064. //**********************************Write to File********************************************************/
  9065. FILE *infile;
  9066. FILE *outfile;
  9067. // open file for writing
  9068. infile = fopen (filename, "r");
  9069. outfile = fopen (tempfile, "w");
  9070. int d =0;
  9071. d = fgetc(infile);
  9072. //DEBUG_INFO("d:%d\n",d);
  9073. rewind(infile);
  9074. //*璉 瘚 辣蝏     1嚗   0 */
  9075. if(d == EOF)
  9076. {
  9077. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9078. fprintf(outfile,"%s\n",payload);
  9079. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9080. fclose(infile);
  9081. fclose(outfile);
  9082. sprintf(rmFileCmd,"rm -f %s",filename);
  9083. system(rmFileCmd);
  9084. rename(tempfile, filename);
  9085. sleep(1);
  9086. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9087. //system(rmFileCmd);
  9088. }
  9089. else
  9090. {
  9091. char buf[1000]={0};
  9092. int ChargingProfileAdded = FALSE;
  9093. while (fgets(buf, sizeof(buf), infile) != NULL)
  9094. {
  9095. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9096. //*************************tempconnectorIdInt*********************************/
  9097. loc = strstr(buf, "connectorId");
  9098. c = 0;
  9099. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9100. while (loc[strlen("connectorId")+2+c] != ',')
  9101. {
  9102. sstr[c] = loc[strlen("connectorId")+2+c];
  9103. c++;
  9104. }
  9105. sstr[c] = '\0';
  9106. tempconnectorIdInt = atoi(sstr);
  9107. //*************************tempchargingProfileIdInt*********************************/
  9108. loc = strstr(buf, "chargingProfileId");
  9109. c = 0;
  9110. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9111. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9112. {
  9113. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9114. c++;
  9115. }
  9116. sstr[c] = '\0';
  9117. tempchargingProfileIdInt = atoi(sstr);
  9118. //*************************tempstackLevelInt*********************************/
  9119. loc = strstr(buf, "stackLevel");
  9120. c = 0;
  9121. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9122. while (loc[strlen("stackLevel")+2+c] != ',')
  9123. {
  9124. sstr[c] = loc[strlen("stackLevel")+2+c];
  9125. c++;
  9126. }
  9127. sstr[c] = '\0';
  9128. tempstackLevelInt = atoi(sstr);
  9129. //*************************tempchargingProfilePurposeStr*********************************/
  9130. loc = strstr(payload, "chargingProfilePurpose");
  9131. c = 0;
  9132. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9133. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9134. {
  9135. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9136. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9137. c++;
  9138. }
  9139. sstr[c] = '\0';
  9140. strcpy(tempchargingProfilePurposeStr,sstr);
  9141. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9142. {
  9143. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9144. {
  9145. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9146. if(ChargingProfileAdded == FALSE)
  9147. {
  9148. fprintf(outfile,"%s\n",payload);
  9149. ChargingProfileAdded = TRUE;
  9150. }
  9151. }
  9152. else
  9153. {
  9154. if(tempstackLevelInt < stackLevelInt)
  9155. {
  9156. if(ChargingProfileAdded == FALSE)
  9157. {
  9158. fprintf(outfile,"%s\n",payload);
  9159. ChargingProfileAdded = TRUE;
  9160. fprintf(outfile,"%s\n",buf);
  9161. }
  9162. else
  9163. {
  9164. fprintf(outfile,"%s\n",buf);
  9165. }
  9166. }
  9167. else
  9168. {
  9169. if(ChargingProfileAdded == FALSE)
  9170. {
  9171. fprintf(outfile,"%s\n",buf);
  9172. fprintf(outfile,"%s\n",payload);
  9173. ChargingProfileAdded = TRUE;
  9174. }
  9175. else
  9176. {
  9177. fprintf(outfile,"%s\n",buf);
  9178. }
  9179. }
  9180. }
  9181. }
  9182. else
  9183. {
  9184. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9185. {
  9186. if(ChargingProfileAdded == FALSE)
  9187. {
  9188. fprintf(outfile,"%s\n",payload);
  9189. ChargingProfileAdded = TRUE;
  9190. fprintf(outfile,"%s\n",buf);
  9191. }
  9192. else
  9193. {
  9194. fprintf(outfile,"%s\n",buf);
  9195. }
  9196. }
  9197. else if(tempstackLevelInt < stackLevelInt)
  9198. {
  9199. if(ChargingProfileAdded == FALSE)
  9200. {
  9201. fprintf(outfile,"%s\n",payload);
  9202. ChargingProfileAdded = TRUE;
  9203. fprintf(outfile,"%s\n",buf);
  9204. }
  9205. else
  9206. {
  9207. fprintf(outfile,"%s\n",buf);
  9208. }
  9209. }
  9210. else
  9211. {
  9212. if(ChargingProfileAdded == FALSE)
  9213. {
  9214. fprintf(outfile,"%s\n",buf);
  9215. fprintf(outfile,"%s\n",payload);
  9216. ChargingProfileAdded = TRUE;
  9217. }
  9218. else
  9219. {
  9220. fprintf(outfile,"%s\n",buf);
  9221. }
  9222. }
  9223. }
  9224. } // end of while loop
  9225. fclose(infile);
  9226. fclose(outfile);
  9227. sprintf(rmFileCmd,"rm -f %s",filename);
  9228. system(rmFileCmd);
  9229. rename(tempfile, filename);
  9230. sleep(1);
  9231. result = TRUE;
  9232. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9233. }
  9234. end:
  9235. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9236. return result;
  9237. return result;
  9238. }
  9239. int handleTriggerMessageRequest(char *uuid, char *payload)
  9240. {
  9241. mtrace();
  9242. int result = FAIL;
  9243. int connectorIdIsNULL = FALSE;
  9244. int connectorIdInt =0;
  9245. char sstr[40]={0},sstrtemp[100]={ 0 };
  9246. char requestedMessagestr[40]={0};
  9247. char comfirmstr[20]={0};
  9248. int c = 0;
  9249. char *loc;
  9250. DEBUG_INFO("handleTriggerMessageRequest\n");
  9251. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9252. strcpy(sstrtemp, stringtrimspace(payload));
  9253. c = 0;
  9254. loc = strstr(sstrtemp, "requestedMessage");
  9255. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9256. {
  9257. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9258. c++;
  9259. }
  9260. sstr[c] = '\0';
  9261. strcpy(requestedMessagestr, sstr);
  9262. c = 0;
  9263. loc = strstr(sstrtemp, "connectorId");
  9264. if(loc == NULL)
  9265. {
  9266. connectorIdIsNULL = TRUE;
  9267. }
  9268. else
  9269. {
  9270. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9271. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9272. {
  9273. sstr[c] = loc[strlen("connectorId")+2+c];
  9274. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9275. c++;
  9276. }
  9277. sstr[c] = '\0';
  9278. connectorIdInt = atoi(sstr);
  9279. }
  9280. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9281. {
  9282. //connectorIdInt = json_object_get_int(connectorId);
  9283. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9284. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9285. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9286. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9287. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9288. }
  9289. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9290. {
  9291. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9292. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9293. return TRUE;
  9294. }
  9295. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9296. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9297. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9298. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9299. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9300. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9301. {
  9302. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9303. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9304. return TRUE;
  9305. }
  9306. else
  9307. {
  9308. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9309. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9310. }
  9311. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9312. {
  9313. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9314. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9315. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9316. {
  9317. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9318. }
  9319. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9320. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9321. }
  9322. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9323. {
  9324. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9325. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9326. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9327. }
  9328. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9329. {
  9330. sendBootNotificationRequest();
  9331. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9332. }
  9333. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9334. {
  9335. sendHeartbeatRequest(connectorIdInt);
  9336. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9337. }
  9338. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9339. {
  9340. if(connectorIdIsNULL == FALSE)
  9341. {
  9342. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9343. {
  9344. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9345. sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9346. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9347. }
  9348. }
  9349. else
  9350. {
  9351. for(int idx=0;idx< gunTotalNumber;idx++)
  9352. {
  9353. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9354. sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9355. }
  9356. }
  9357. }
  9358. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9359. {
  9360. if(connectorIdIsNULL == FALSE)
  9361. {
  9362. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9363. {
  9364. sendStatusNotificationRequest(connectorIdInt -1);
  9365. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9366. }
  9367. }
  9368. else
  9369. {
  9370. for(int idx=0;idx< gunTotalNumber;idx++)
  9371. sendStatusNotificationRequest(idx);
  9372. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9373. }
  9374. }
  9375. return result;
  9376. }
  9377. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9378. {
  9379. mtrace();
  9380. int result = FAIL;
  9381. char sstr[6]={0},sstrtemp[50]={ 0 };
  9382. int connectorIdInt =0;
  9383. char comfirmstr[20]={0};
  9384. int c = 0;
  9385. int tempIndex = 0;
  9386. char *loc;
  9387. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9388. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9389. strcpy(sstrtemp, stringtrimspace(payload));
  9390. c = 0;
  9391. loc = strstr(sstrtemp, "connectorId");
  9392. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9393. while (loc[strlen("connectorId")+2+c] != '}')
  9394. {
  9395. sstr[c] = loc[strlen("connectorId")+2+c];
  9396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9397. c++;
  9398. }
  9399. sstr[c] = '\0';
  9400. connectorIdInt = atoi(sstr);
  9401. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9402. if(gunTotalNumber == 0)
  9403. {
  9404. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9405. goto end;
  9406. }
  9407. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9408. {
  9409. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9410. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9411. goto end;
  9412. }
  9413. else
  9414. {
  9415. //check Transaction active
  9416. if(gunType[connectorIdInt-1] == 'J')
  9417. {
  9418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9419. {
  9420. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9421. }
  9422. else
  9423. {
  9424. tempIndex = connectorIdInt -1;
  9425. }
  9426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9427. {
  9428. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9429. {
  9430. //stop Transaction
  9431. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9432. }
  9433. }
  9434. }
  9435. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9436. {
  9437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9438. {
  9439. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9440. }
  9441. else
  9442. {
  9443. tempIndex = connectorIdInt -1;
  9444. }
  9445. for (int index = 0; index < CCS_QUANTITY; index++)
  9446. {
  9447. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9448. {
  9449. //stop Transaction
  9450. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9451. }
  9452. }
  9453. }
  9454. else if(gunType[connectorIdInt-1] == 'G')
  9455. {
  9456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9457. {
  9458. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9459. }
  9460. else
  9461. {
  9462. tempIndex = connectorIdInt -1;
  9463. }
  9464. for (int index = 0; index < GB_QUANTITY; index++)
  9465. {
  9466. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9467. {
  9468. //stop Transaction
  9469. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9470. }
  9471. }
  9472. }
  9473. else
  9474. {
  9475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9476. {
  9477. tempIndex = 2;
  9478. }
  9479. else
  9480. {
  9481. tempIndex = connectorIdInt-1;
  9482. }
  9483. for (int index = 0; index < AC_QUANTITY; index++)
  9484. {
  9485. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9486. {
  9487. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9488. }
  9489. }
  9490. }
  9491. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9492. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9493. result = TRUE;
  9494. return result;
  9495. }
  9496. end:
  9497. //json_object_put(obj); --- remove temporally
  9498. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9499. return result;
  9500. }
  9501. static char UpdateFirmwarepayloadData[300]={0};
  9502. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9503. {
  9504. mtrace();
  9505. int result = FAIL;
  9506. pthread_t t;
  9507. sendUpdateFirmwareConfirmation(uuid);
  9508. memset(UpdateFirmwarepayloadData, 0, 300);
  9509. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9510. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9511. ////pthread_join(t, NULL); //
  9512. //pthread_detach(t);
  9513. //sendUpdateFirmwareConfirmation(uuid);
  9514. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9515. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9516. return result;
  9517. }
  9518. void *UpdateFirmwareProcess(void *data)
  9519. {
  9520. pthread_detach(pthread_self());
  9521. mtrace();
  9522. int retriesInt =0, retryIntervalInt=0;
  9523. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9524. int port=0;
  9525. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9526. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9527. //char comfirmstr[20];
  9528. int isSuccess = 0;
  9529. char ftpbuf[200];
  9530. char temp[100];
  9531. char * pch;
  9532. int retriesISNULL=FALSE;
  9533. int retryInterval=FALSE;
  9534. int c = 0;
  9535. //int i = 0;
  9536. char *loc;
  9537. char sstr[300]={ 0 };
  9538. char str[300]={ 0 };
  9539. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9540. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9541. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9542. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9543. //***************location **************/
  9544. loc = strstr(str, "location");
  9545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9546. c = 0;
  9547. while (loc[3+strlen("location")+c] != '\"')
  9548. {
  9549. sstr[c] = loc[3+strlen("location")+c];
  9550. c++;
  9551. }
  9552. sstr[c] = '\0';
  9553. strcpy(locationstr, sstr);
  9554. //***************retries**************/
  9555. c = 0;
  9556. loc = strstr(str, "retries");
  9557. if(loc == NULL)
  9558. {
  9559. retriesISNULL=TRUE;
  9560. }
  9561. else
  9562. {
  9563. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9564. while (loc[strlen("retries")+2+c] != ',')
  9565. {
  9566. sstr[c] = loc[strlen("retries")+2+c];
  9567. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9568. c++;
  9569. }
  9570. sstr[c] = '\0';
  9571. }
  9572. if(retriesISNULL == FALSE)
  9573. {
  9574. retriesInt = atoi(sstr);
  9575. }
  9576. //***************retrieveDate **************/
  9577. loc = strstr(str, "retrieveDate");
  9578. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9579. c = 0;
  9580. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9581. {
  9582. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9583. c++;
  9584. }
  9585. sstr[c] = '\0';
  9586. strcpy(retrieveDatestr, sstr);
  9587. //***************retryInterval **************/
  9588. c = 0;
  9589. loc = strstr(str, "retryInterval");
  9590. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9591. if(loc == NULL)
  9592. {
  9593. retryInterval=TRUE;
  9594. }
  9595. else
  9596. {
  9597. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9598. {
  9599. sstr[c] = loc[strlen("retryInterval")+2+c];
  9600. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9601. c++;
  9602. }
  9603. sstr[c] = '\0';
  9604. }
  9605. if(retryInterval==FALSE)
  9606. {
  9607. retryIntervalInt = atoi(sstr);
  9608. }
  9609. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9610. memset(path, 0, ARRAY_SIZE(path));
  9611. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9612. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9613. if(strncmp(locationstr,"http", 4) == 0)
  9614. {
  9615. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9616. protocol, host, path);
  9617. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9618. // protocol, user, password, host, path);
  9619. sprintf(ftppath,"/%s", path);
  9620. //DEBUG_INFO("protocol =%s\n",protocol);
  9621. //DEBUG_INFO("host =%s\n",host);
  9622. //DEBUG_INFO("path =%s\n",path);
  9623. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9624. int ftppathlen=strlen(ftppath);
  9625. int i=1;
  9626. char filenametemp[50];
  9627. while(i < ftppathlen)
  9628. {
  9629. int len=ftppathlen-i;
  9630. if(ftppath[len]== 47) // '/' ascll code: 47
  9631. {
  9632. DEBUG_INFO("compare '/' all right\n");
  9633. break;
  9634. }
  9635. i=i+1;
  9636. }
  9637. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9638. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9639. filenametemp[i+1] = 0;
  9640. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9641. do{
  9642. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9643. sleep(retryIntervalInt);
  9644. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9645. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9646. if(!isSuccess)
  9647. {
  9648. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9649. }
  9650. else
  9651. {
  9652. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9653. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9654. //isUpdateRequest = TRUE;
  9655. }
  9656. }
  9657. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9658. {
  9659. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9660. memset(temp, 0, ARRAY_SIZE(temp));
  9661. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9662. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9663. int ftppathlen=strlen(ftpbuf);
  9664. int i=1;
  9665. char filenametemp[50];
  9666. while(i < ftppathlen)
  9667. {
  9668. int len=ftppathlen-i;
  9669. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9670. {
  9671. DEBUG_INFO(" compare '/' all right\n");
  9672. break;
  9673. }
  9674. i=i+1;
  9675. }
  9676. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9677. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9678. filenametemp[i+1] = 0;
  9679. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9680. pch=strchr(temp,'@');
  9681. if(pch==NULL)
  9682. {
  9683. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9684. protocol, host, &port, path);
  9685. strcpy(user,"anonymous");
  9686. strcpy(password,"");
  9687. }
  9688. else
  9689. {
  9690. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9691. protocol, user, password, host, &port, path);
  9692. }
  9693. sscanf(host,"%[^/]%s",host1, path1);
  9694. sprintf(ftppath,"%s", path1);
  9695. //DEBUG_INFO("protocol =%s\n",protocol);
  9696. //DEBUG_INFO("user =%s\n",user);
  9697. //DEBUG_INFO("password =%s\n",password);
  9698. //DEBUG_INFO("host1 =%s\n",host1);
  9699. //DEBUG_INFO("port =%d\n",port);
  9700. //DEBUG_INFO("path1 =%s\n",path1);
  9701. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9702. //ftpFile(host, user, password, port, ftppath, fname);
  9703. //download firmware pthred
  9704. if(port == 0)
  9705. {
  9706. port = 21;
  9707. }
  9708. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9709. do{
  9710. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9711. sleep(retryIntervalInt);
  9712. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9713. if(!isSuccess)
  9714. {
  9715. //BulldogUtil.sleepMs(interval*1000);
  9716. DEBUG_INFO("Update firmware request and download file fail.\n");
  9717. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9718. }
  9719. else
  9720. {
  9721. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9722. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9723. //isUpdateRequest = TRUE;
  9724. }
  9725. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9726. }
  9727. else
  9728. {
  9729. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9730. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9731. }
  9732. pthread_exit(NULL);
  9733. }
  9734. //==========================================
  9735. // Handle server response routine
  9736. //==========================================
  9737. void handleAuthorizeResponse(char *payload, int gun_index)
  9738. {
  9739. mtrace();
  9740. char expiryDatestr[30]={0};
  9741. char parentIdTagstr[20]={0};
  9742. char statusstr[20]={0};
  9743. char expiryDatestrtemp[30]={0};
  9744. char parentIdTagstrtemp[20]={0};
  9745. char IdTagstrtemp[20]={0};
  9746. char statusstrtemp[20]={0};
  9747. int expiryDateISNULL=FALSE;
  9748. int parentIdTagISNULL=FALSE;
  9749. char sstr[160]={0};
  9750. char* filename = AuthorizationCache_JSON;
  9751. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9752. char *loc;
  9753. int resultRename=0;
  9754. int responseIdTagInfoAsZero= 0;
  9755. char rmFileCmd[50]={0};
  9756. DEBUG_INFO("handleAuthorizeResponse...\n");
  9757. json_object *Authorize;
  9758. Authorize = json_tokener_parse(payload);
  9759. if(!is_error(Authorize))
  9760. {
  9761. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9762. {
  9763. // Required data
  9764. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9765. // Optional data
  9766. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9767. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9768. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9769. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9770. }
  9771. }
  9772. json_object_put(Authorize);
  9773. if(expiryDateISNULL == FALSE)
  9774. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9775. if(parentIdTagISNULL == FALSE)
  9776. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9777. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9778. //Update idTag information to authorization cache if supproted
  9779. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9780. {
  9781. if((access(filename,F_OK))!=-1)
  9782. {
  9783. printf("AuthorizationCache exist.\n");
  9784. }
  9785. else
  9786. {
  9787. printf("AuthorizationCache not exist\n");
  9788. FILE *log = fopen(filename, "w+");
  9789. if(log == NULL)
  9790. {
  9791. printf("log is NULL\n");
  9792. goto out;
  9793. }
  9794. else
  9795. {
  9796. fclose(log);
  9797. }
  9798. }
  9799. FILE *infile;
  9800. FILE *outfile;
  9801. // open file for writing
  9802. infile = fopen (filename, "r");
  9803. outfile = fopen (tempfile, "w");
  9804. int c;
  9805. c = fgetc(infile);
  9806. //DEBUG_INFO("c:%d\n",c);
  9807. rewind(infile);
  9808. if(c == EOF)
  9809. {
  9810. DEBUG_INFO("Orignal File is NULL\n");
  9811. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9812. {
  9813. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9814. }
  9815. else
  9816. {
  9817. strcpy(expiryDatestrtemp, "");
  9818. }
  9819. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9820. {
  9821. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9822. }
  9823. else
  9824. {
  9825. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9826. }
  9827. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9828. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9829. fclose(infile);
  9830. fclose(outfile);
  9831. sprintf(rmFileCmd,"rm -f %s",filename);
  9832. system(rmFileCmd);
  9833. resultRename = rename(tempfile, filename);
  9834. if(resultRename == 0)
  9835. {
  9836. printf("File renamed successfully");
  9837. }
  9838. else
  9839. {
  9840. printf("Error: unable to rename the file");
  9841. }
  9842. }
  9843. else
  9844. {
  9845. char buf[160]={0};
  9846. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9847. {
  9848. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9849. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9850. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9851. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9852. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9853. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9854. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9855. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9856. //------------------IdTag-----------------------
  9857. loc = strstr(buf, "idTag");
  9858. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9859. c = 0;
  9860. while (loc[3+strlen("idTag")+c] != '\"')
  9861. {
  9862. sstr[c] = loc[3+strlen("idTag")+c];
  9863. c++;
  9864. }
  9865. sstr[c] = '\0';
  9866. strcpy(IdTagstrtemp,sstr);
  9867. //*********************expiryDate***************/
  9868. loc = strstr(buf, "expiryDate");
  9869. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9870. c = 0;
  9871. while (loc[3+strlen("expiryDate")+c] != '\"')
  9872. {
  9873. sstr[c] = loc[3+strlen("expiryDate")+c];
  9874. c++;
  9875. }
  9876. sstr[c] = '\0';
  9877. strcpy(expiryDatestr,sstr);
  9878. //*********************parentIdTag***************/
  9879. loc = strstr(buf, "parentIdTag");
  9880. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9881. c = 0;
  9882. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9883. {
  9884. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9885. c++;
  9886. }
  9887. sstr[c] = '\0';
  9888. strcpy(parentIdTagstr,sstr);
  9889. //*********************status***************/
  9890. loc = strstr(buf, "status");
  9891. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9892. c = 0;
  9893. while (loc[3+strlen("status")+c] != '\"')
  9894. {
  9895. sstr[c] = loc[3+strlen("status")+c];
  9896. c++;
  9897. }
  9898. sstr[c] = '\0';
  9899. strcpy(statusstr,sstr);
  9900. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9901. {
  9902. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9903. responseIdTagInfoAsZero = 1;
  9904. }
  9905. else
  9906. {
  9907. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9908. }
  9909. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9910. {
  9911. //modify item
  9912. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9913. {
  9914. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9915. }
  9916. else
  9917. {
  9918. strcpy(expiryDatestrtemp, "");
  9919. }
  9920. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9921. {
  9922. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9923. }
  9924. else
  9925. {
  9926. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9927. }
  9928. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9929. }
  9930. else
  9931. {
  9932. //wrie original item
  9933. strcpy(expiryDatestrtemp, expiryDatestr);
  9934. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9935. strcpy(statusstrtemp, statusstr);
  9936. }
  9937. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9938. }
  9939. fclose(infile);
  9940. fclose(outfile);
  9941. sprintf(rmFileCmd,"rm -f %s",filename);
  9942. system(rmFileCmd);
  9943. resultRename = rename(tempfile, filename);
  9944. if(resultRename == 0)
  9945. {
  9946. DEBUG_INFO("File renamed successfully");
  9947. }
  9948. else
  9949. {
  9950. DEBUG_INFO("Error: unable to rename the file");
  9951. }
  9952. }
  9953. }
  9954. out:
  9955. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9956. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9957. authorizeRetryTimes = 0;
  9958. }
  9959. char * strtrimc( char * s )
  9960. {
  9961. char * p1 = s;
  9962. char * p2 = s;
  9963. while(*p1 != '\0')
  9964. {
  9965. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9966. {
  9967. if(*p1 != ',')
  9968. {
  9969. p1 ++;
  9970. }
  9971. else
  9972. {
  9973. break;
  9974. }
  9975. }
  9976. if(*p1 != ',')
  9977. {
  9978. * p2 ++ = *p1 ++;
  9979. //printf("p2=%s\n",p2);
  9980. }
  9981. else
  9982. {
  9983. break;
  9984. }
  9985. }
  9986. *p2 = '\0';
  9987. return (s);
  9988. }
  9989. void handleBootNotificationResponse(char *payload, int gun_index)
  9990. {
  9991. mtrace();
  9992. char statusStr[12]={0};
  9993. char currentTimeStr[30]={0};
  9994. int intervalInt = 0;
  9995. struct tm tp;
  9996. char buf[28]={0};
  9997. char timebuf[50]={0};
  9998. DEBUG_INFO("handleBootNotificationResponse...\n");
  9999. json_object *BootNotification;
  10000. BootNotification = json_tokener_parse(payload);
  10001. if(!is_error(BootNotification))
  10002. {
  10003. // Required data
  10004. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10005. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10006. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10007. }
  10008. json_object_put(BootNotification);
  10009. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10010. BootNotificationInterval = intervalInt;
  10011. HeartBeatWaitTime = intervalInt;
  10012. //write back to ShmOCPP16Data->BootNotification
  10013. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10014. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10015. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10016. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10017. {
  10018. server_sign = TRUE;
  10019. server_pending =FALSE;
  10020. }
  10021. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10022. {
  10023. server_pending = TRUE;
  10024. }
  10025. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10026. tp.tm_isdst = -1;
  10027. //time_t utc = mktime(&tp);
  10028. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10029. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10030. sprintf(timebuf,"date -s '%s'",buf);
  10031. system(timebuf);
  10032. srand(time(NULL));
  10033. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10034. //==============================================
  10035. // RTC sync
  10036. //==============================================
  10037. system("/sbin/hwclock -w --systohc");
  10038. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10039. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10040. }
  10041. void handleDataTransferResponse(char *payload, int gun_index)
  10042. {
  10043. char sstr[160]={0};//sstr[200]={ 0 };
  10044. int c = 0;
  10045. char *loc;
  10046. DEBUG_INFO("handleDataTransferResponse ...\n");
  10047. loc = strstr(payload, "status");
  10048. printf("loc=%s\n",loc);
  10049. c = 0;
  10050. while (loc[3+strlen("status")+c] != '\"')
  10051. {
  10052. sstr[c] = loc[3+strlen("status")+c];
  10053. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10054. c++;
  10055. }
  10056. sstr[c] = '\0';
  10057. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10058. }
  10059. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10060. {
  10061. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10062. //struct json_object *obj;
  10063. // obj = json_tokener_parse(payload);
  10064. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10065. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10066. //No fields are defined.
  10067. }
  10068. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10069. {
  10070. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10071. //struct json_object *obj;
  10072. // obj = json_tokener_parse(payload);
  10073. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10074. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10075. //No fields are defined.
  10076. }
  10077. void handleHeartbeatResponse(char *payload, int gun_index)
  10078. {
  10079. mtrace();
  10080. struct tm tp;
  10081. char buf[28]={0};
  10082. char timebuf[50]={0};
  10083. DEBUG_INFO("handleHeartbeatResponse...\n");
  10084. json_object *Heartbeat;
  10085. Heartbeat = json_tokener_parse(payload);
  10086. if(!is_error(Heartbeat))
  10087. {
  10088. // Required data
  10089. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10090. }
  10091. json_object_put(BootNotification);
  10092. if(FirstHeartBeat == 0)
  10093. {
  10094. FirstHeartBeat = 1;
  10095. DEBUG_INFO("FirstHeartBeat \n");
  10096. }
  10097. HeartBeatWithNOResponse = 0;
  10098. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10099. tp.tm_isdst = -1;
  10100. //time_t utc = mktime(&tp);
  10101. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10102. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10103. sprintf(timebuf,"date -s '%s'",buf);
  10104. system(timebuf);
  10105. //==============================================
  10106. // RTC sync
  10107. //==============================================
  10108. system("/sbin/hwclock -w --systohc");
  10109. //===============================================
  10110. //Print Out HeartBeat log
  10111. //===============================================
  10112. {
  10113. double diff_t;
  10114. struct tm tp,tp1;
  10115. // BootNotification Receive Time
  10116. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10117. tp.tm_isdst = -1;
  10118. time_t BootNotificationReceiveTime = mktime(&tp);
  10119. //HeartBeat Receive Time
  10120. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10121. tp1.tm_isdst = -1;
  10122. time_t HeartBeatReceiveTime = mktime(&tp1);
  10123. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10124. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10125. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10126. {
  10127. HeartBeatCountPerHour = (int)diff_t / 3600;
  10128. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10129. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10130. }
  10131. }
  10132. }
  10133. void handleMeterValuesResponse(char *payload, int gun_index)
  10134. {
  10135. mtrace();
  10136. DEBUG_INFO("handleMeterValuesResponse...\n");
  10137. }
  10138. void handleStartTransactionResponse(char *payload, int gun_index)
  10139. {
  10140. mtrace();
  10141. //int transactionIdInt = 0;
  10142. FILE *outfile;
  10143. char data[100]={0};
  10144. DEBUG_INFO("handleStartTransactionResponse...\n");
  10145. json_object *StartTransaction;
  10146. StartTransaction = json_tokener_parse(payload);
  10147. if(!is_error(StartTransaction))
  10148. {
  10149. // Required data
  10150. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10151. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10152. // Optional data
  10153. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10154. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10155. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10156. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10157. }
  10158. json_object_put(StartTransaction);
  10159. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10160. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10161. //-----------Start : write to the Queue TransactionId file -----------------//
  10162. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10163. {}
  10164. else
  10165. {
  10166. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10167. if(log == NULL)
  10168. {
  10169. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10170. return ;
  10171. }
  10172. else
  10173. {
  10174. fclose(log);
  10175. }
  10176. }
  10177. // open file for writing
  10178. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10179. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10180. {
  10181. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10182. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10183. fputs(data, outfile);
  10184. fclose (outfile);
  10185. }
  10186. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10187. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10188. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10189. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10190. }
  10191. void handleStatusNotificationResponse(char *payload, int gun_index)
  10192. {
  10193. mtrace();
  10194. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10195. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10196. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10197. }
  10198. void handleStopTransactionnResponse(char *payload, int gun_index)
  10199. {
  10200. mtrace();
  10201. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10202. json_object *StopTransaction;
  10203. StopTransaction = json_tokener_parse(payload);
  10204. if(!is_error(StopTransaction))
  10205. {
  10206. // Optional data
  10207. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10208. {
  10209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10210. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10212. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10214. }
  10215. }
  10216. json_object_put(StopTransaction);
  10217. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10218. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10219. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10220. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10221. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10222. }
  10223. //==========================================
  10224. // Handle Error routine
  10225. //==========================================
  10226. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10227. {
  10228. mtrace();
  10229. #ifdef SystemLogMessage
  10230. DEBUG_INFO("errorCode: %s\n", errorCode);
  10231. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10232. DEBUG_INFO("errorDetails: %s\n", payload);
  10233. #endif
  10234. }
  10235. //===============================================
  10236. // Common routine
  10237. //===============================================
  10238. int initialConfigurationTable(void)
  10239. {
  10240. //clock_t start_t, end_t, total_t;
  10241. FILE *fp;
  10242. FILE *outfile;
  10243. char str[200]={0};
  10244. char sstr[100]={0};
  10245. int c = 0;
  10246. char *loc;
  10247. DEBUG_INFO("initialConfigurationTable...\n");
  10248. //start_t = clock();
  10249. //printf("Starting of the program, start_t = %ld\n", start_t);
  10250. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10251. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10252. {
  10253. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10254. if(outfile == NULL)
  10255. {
  10256. DEBUG_INFO("Error opening file\n");
  10257. return FALSE;
  10258. }
  10259. /*Core Profile*/
  10260. //AllowOfflineTxForUnknownId
  10261. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10262. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10266. //AuthorizationCacheEnabled
  10267. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10271. //AuthorizeRemoteTxRequests
  10272. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10276. //BlinkRepeat
  10277. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10281. //ClockAlignedDataInterval
  10282. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10286. //ConnectionTimeOut
  10287. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10291. //GetConfigurationMaxKeys
  10292. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10296. // HeartbeatInterval
  10297. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10301. // LightIntensity
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10306. // LocalAuthorizeOffline
  10307. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10311. // LocalPreAuthorize
  10312. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10316. // MaxEnergyOnInvalidId
  10317. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10320. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10322. // MeterValuesAlignedData
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10327. else
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10330. // MeterValuesAlignedDataMaxLength
  10331. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10335. else
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10338. // MeterValuesSampledData
  10339. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10343. else
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10346. // MeterValuesSampledDataMaxLength
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10351. else
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10354. // MeterValueSampleInterval
  10355. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10359. // MinimumStatusDuration
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10363. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10365. // NumberOfConnectors
  10366. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10369. {
  10370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10371. }
  10372. else
  10373. {
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10375. }
  10376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10377. // ResetRetries
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10382. // ConnectorPhaseRotation
  10383. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10387. // ConnectorPhaseRotationMaxLength
  10388. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10392. // StopTransactionOnEVSideDisconnect
  10393. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10397. // StopTransactionOnInvalidId
  10398. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10402. // StopTxnAlignedData
  10403. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10407. // StopTxnAlignedDataMaxLength
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10412. // StopTxnSampledData
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10417. else
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10420. // StopTxnSampledDataMaxLength
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10423. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10424. {
  10425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10426. }
  10427. else
  10428. {
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10430. }
  10431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10432. // SupportedFeatureProfiles
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10437. // SupportedFeatureProfilesMaxLength
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10442. // TransactionMessageAttempts
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10446. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10448. // TransactionMessageRetryInterval
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10452. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10454. // UnlockConnectorOnEVSideDisconnect
  10455. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10459. // WebSocketPingInterval
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10464. //* Local Auth List Management Profile*/
  10465. #if 0
  10466. //For OCTT Test Case
  10467. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10470. #endif
  10471. #if 1
  10472. //LocalAuthListEnabled
  10473. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10477. #endif
  10478. //LocalAuthListMaxLength
  10479. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10483. //SendLocalListMaxLength
  10484. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10488. //ReserveConnectorZeroSupported
  10489. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10493. //* Smart Charging Profile */
  10494. //ChargeProfileMaxStackLevel
  10495. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10499. // ChargingScheduleAllowedChargingRateUnit
  10500. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10504. // ChargingScheduleMaxPeriods
  10505. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10509. // ConnectorSwitch3to1PhaseSupported
  10510. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10514. // MaxChargingProfilesInstalled
  10515. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10519. fclose(outfile);
  10520. }
  10521. else
  10522. {
  10523. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10524. char keystr[60]={0};
  10525. char readonlystr[10]={0};
  10526. char valuestr[100]={0};
  10527. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10528. if(fp == NULL) {
  10529. DEBUG_INFO("Error opening file");
  10530. return FALSE;
  10531. }
  10532. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10533. {
  10534. //DEBUG_INFO("Get Configuration \n");
  10535. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10536. //*************************key*********************************/
  10537. loc = strstr(str, "key");
  10538. c = 0;
  10539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10540. while (loc[strlen("key")+3+c] != '\"')
  10541. {
  10542. sstr[c] = loc[strlen("key")+3+c];
  10543. c++;
  10544. }
  10545. sstr[c] = '\0';
  10546. strcpy(keystr,sstr);
  10547. //*************************readonly*********************************/
  10548. loc = strstr(str, "readonly");
  10549. c = 0;
  10550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10551. while (loc[strlen("readonly")+2+c] != ',')
  10552. {
  10553. sstr[c] = loc[strlen("readonly")+2+c];
  10554. c++;
  10555. }
  10556. sstr[c] = '\0';
  10557. strcpy(readonlystr,sstr);
  10558. //*************************value*********************************/
  10559. loc = strstr(str, "value");
  10560. c = 0;
  10561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10562. while (loc[strlen("value")+3+c] != '\"')
  10563. {
  10564. sstr[c] = loc[strlen("value")+3+c];
  10565. c++;
  10566. }
  10567. sstr[c] = '\0';
  10568. strcpy(valuestr,sstr);
  10569. // DEBUG_INFO("keystr=%s\n",keystr);
  10570. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10571. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10572. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10573. {
  10574. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10577. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10578. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10579. }
  10580. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10581. {
  10582. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10585. }
  10586. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10587. {
  10588. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10590. }
  10591. if(strcmp(keystr, "BlinkRepeat") == 0)
  10592. {
  10593. //Charger.BlinkRepeat = Integer.parseInt(value);
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10596. }
  10597. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10598. {
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10601. }
  10602. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10603. {
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10606. }
  10607. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10611. }
  10612. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10613. {
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10616. HeartBeatWaitTime = atoi(valuestr);
  10617. }
  10618. if(strcmp(keystr, "LightIntensity") == 0)
  10619. {
  10620. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10622. }
  10623. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10624. {
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10627. }
  10628. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10629. {
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10632. }
  10633. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10637. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10638. }
  10639. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10640. {
  10641. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10643. }
  10644. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10645. {
  10646. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10648. }
  10649. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10650. {
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10653. }
  10654. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10655. {
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10658. }
  10659. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10660. {
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10663. }
  10664. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10665. {
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10668. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10669. }
  10670. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10671. {
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10674. }
  10675. if(strcmp(keystr, "ResetRetries") == 0)
  10676. {
  10677. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10679. }
  10680. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10681. {
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10684. }
  10685. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10686. {
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10689. }
  10690. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10691. {
  10692. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10694. }
  10695. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10696. {
  10697. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10699. }
  10700. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10701. {
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10704. }
  10705. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10706. {
  10707. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10709. }
  10710. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10711. {
  10712. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10714. }
  10715. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10716. {
  10717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10719. }
  10720. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10721. {
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10724. }
  10725. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10726. {
  10727. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10729. }
  10730. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10731. {
  10732. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10734. TransactionMessageAttemptsValue = atoi(valuestr);
  10735. }
  10736. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10737. {
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10740. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10741. }
  10742. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10743. {
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10746. }
  10747. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10748. {
  10749. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10751. }
  10752. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10753. {
  10754. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10756. }
  10757. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10758. {
  10759. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10761. }
  10762. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10763. {
  10764. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10766. }
  10767. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10768. {
  10769. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10771. }
  10772. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10773. {
  10774. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10776. }
  10777. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10778. {
  10779. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10781. }
  10782. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10783. {
  10784. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10786. }
  10787. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10788. {
  10789. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10791. }
  10792. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10793. {
  10794. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10796. }
  10797. }
  10798. fclose(fp);
  10799. }
  10800. return 0;
  10801. }
  10802. void StoreConfigurationTable(void)
  10803. {
  10804. FILE *outfile;
  10805. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10806. if(outfile == NULL)
  10807. {
  10808. DEBUG_INFO("Error opening file");
  10809. return ;
  10810. }
  10811. /*Core Profile*/
  10812. //AllowOfflineTxForUnknownId
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10815. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10818. */
  10819. //DEBUG_INFO("data=%s\n",data);
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10821. //AuthorizationCacheEnabled
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10828. //AuthorizeRemoteTxRequests
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10835. //BlinkRepeat
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10842. //ClockAlignedDataInterval
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10849. //ConnectionTimeOut
  10850. /*
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10854. */
  10855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10856. //GetConfigurationMaxKeys
  10857. /*
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10861. */
  10862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10863. // HeartbeatInterval
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10870. // LightIntensity
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10877. // LocalAuthorizeOffline
  10878. /*
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10882. */
  10883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10884. // LocalPreAuthorize
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10891. // MaxEnergyOnInvalidId
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10896. */
  10897. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10899. // MeterValuesAlignedData
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10904. */
  10905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10906. // MeterValuesAlignedDataMaxLength
  10907. /*
  10908. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10911. */
  10912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10913. // MeterValuesSampledData
  10914. /*
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10918. */
  10919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10920. // MeterValuesSampledDataMaxLength
  10921. /*
  10922. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10925. */
  10926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10927. // MeterValueSampleInterval
  10928. /*
  10929. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10932. */
  10933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10934. // MinimumStatusDuration
  10935. /*
  10936. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10939. */
  10940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10941. // NumberOfConnectors
  10942. /*
  10943. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10946. {
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10948. }
  10949. else
  10950. {
  10951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10952. }
  10953. */
  10954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10955. // ResetRetries
  10956. /*
  10957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10960. */
  10961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10962. // ConnectorPhaseRotation
  10963. /*
  10964. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10967. */
  10968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10969. // ConnectorPhaseRotationMaxLength
  10970. /*
  10971. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10974. */
  10975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10976. // StopTransactionOnEVSideDisconnect
  10977. /*
  10978. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10981. */
  10982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10983. // StopTransactionOnInvalidId
  10984. /*
  10985. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10988. */
  10989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10990. // StopTxnAlignedData
  10991. /*
  10992. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10995. */
  10996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10997. // StopTxnAlignedDataMaxLength
  10998. /*
  10999. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11002. */
  11003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11004. // StopTxnSampledData
  11005. /*
  11006. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11009. */
  11010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11011. // StopTxnSampledDataMaxLength
  11012. /*
  11013. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11016. */
  11017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11018. // SupportedFeatureProfiles
  11019. /*
  11020. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11023. */
  11024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11025. // SupportedFeatureProfilesMaxLength
  11026. /*
  11027. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11030. */
  11031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11032. // TransactionMessageAttempts
  11033. /*
  11034. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11037. */
  11038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11039. // TransactionMessageRetryInterval
  11040. /*
  11041. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11044. */
  11045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11046. // UnlockConnectorOnEVSideDisconnect
  11047. /*
  11048. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11051. */
  11052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11053. // WebSocketPingInterval
  11054. /*
  11055. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11058. */
  11059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11060. //* Local Auth List Management Profile*/
  11061. //LocalAuthListEnabled
  11062. /*
  11063. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11066. */
  11067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11068. //LocalAuthListMaxLength
  11069. /*
  11070. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11073. */
  11074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11075. //SendLocalListMaxLength
  11076. /*
  11077. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11080. */
  11081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11082. //ReserveConnectorZeroSupported
  11083. /*
  11084. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11087. */
  11088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11089. //* Smart Charging Profile */
  11090. //ChargeProfileMaxStackLevel
  11091. /*
  11092. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11095. */
  11096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11097. // ChargingScheduleAllowedChargingRateUnit
  11098. /*
  11099. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11102. */
  11103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11104. // ChargingScheduleMaxPeriods
  11105. /*
  11106. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11109. */
  11110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11111. // ConnectorSwitch3to1PhaseSupported
  11112. /*
  11113. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11116. */
  11117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11118. // MaxChargingProfilesInstalled
  11119. /*
  11120. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11123. */
  11124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11125. fclose(outfile);
  11126. }
  11127. void getKeyValue(char *keyReq)
  11128. {
  11129. int isEmpty = FALSE;
  11130. int isKnowKey = FALSE;
  11131. DEBUG_INFO("keyReq = %s\n", keyReq);
  11132. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11133. isEmpty = TRUE;
  11134. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11141. }
  11142. else
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11145. }
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11147. isKnowKey = TRUE;
  11148. }
  11149. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11156. }
  11157. else
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11160. }
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11162. isKnowKey = TRUE;
  11163. }
  11164. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11171. }
  11172. else
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11175. }
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11177. isKnowKey = TRUE;
  11178. }
  11179. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11186. }
  11187. else
  11188. {
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11190. }
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11192. isKnowKey = TRUE;
  11193. }
  11194. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11201. }
  11202. else
  11203. {
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11205. }
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11207. isKnowKey = TRUE;
  11208. }
  11209. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11216. }
  11217. else
  11218. {
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11220. }
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11222. isKnowKey = TRUE;
  11223. }
  11224. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11231. }
  11232. else
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11235. }
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11237. isKnowKey = TRUE;
  11238. }
  11239. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11246. }
  11247. else
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11250. }
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11252. isKnowKey = TRUE;
  11253. }
  11254. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11261. }
  11262. else
  11263. {
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11265. }
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11267. isKnowKey = TRUE;
  11268. }
  11269. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11276. }
  11277. else
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11280. }
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11282. isKnowKey = TRUE;
  11283. }
  11284. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11291. }
  11292. else
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11295. }
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11297. isKnowKey = TRUE;
  11298. }
  11299. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11306. }
  11307. else
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11310. }
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11312. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11313. isKnowKey = TRUE;
  11314. }
  11315. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11322. }
  11323. else
  11324. {
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11326. }
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11328. isKnowKey = TRUE;
  11329. }
  11330. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11337. }
  11338. else
  11339. {
  11340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11341. }
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11343. isKnowKey = TRUE;
  11344. }
  11345. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11352. }
  11353. else
  11354. {
  11355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11356. }
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11358. isKnowKey = TRUE;
  11359. }
  11360. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11367. }
  11368. else
  11369. {
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11371. }
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11373. isKnowKey = TRUE;
  11374. }
  11375. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11382. }
  11383. else
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11386. }
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11388. isKnowKey = TRUE;
  11389. }
  11390. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11397. }
  11398. else
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11401. }
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11403. isKnowKey = TRUE;
  11404. }
  11405. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11412. }
  11413. else
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11416. }
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11418. isKnowKey = TRUE;
  11419. }
  11420. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11427. }
  11428. else
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11431. }
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11433. isKnowKey = TRUE;
  11434. }
  11435. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11442. }
  11443. else
  11444. {
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11446. }
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11448. isKnowKey = TRUE;
  11449. }
  11450. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11457. }
  11458. else
  11459. {
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11461. }
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11463. isKnowKey = TRUE;
  11464. }
  11465. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11472. }
  11473. else
  11474. {
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11476. }
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11478. isKnowKey = TRUE;
  11479. }
  11480. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11487. }
  11488. else
  11489. {
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11491. }
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11493. isKnowKey = TRUE;
  11494. }
  11495. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11502. }
  11503. else
  11504. {
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11506. }
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11508. isKnowKey = TRUE;
  11509. }
  11510. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11517. }
  11518. else
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11521. }
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11523. isKnowKey = TRUE;
  11524. }
  11525. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11532. }
  11533. else
  11534. {
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11536. }
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11538. isKnowKey = TRUE;
  11539. }
  11540. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11547. }
  11548. else
  11549. {
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11551. }
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11553. isKnowKey = TRUE;
  11554. }
  11555. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11562. }
  11563. else
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11566. }
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11568. isKnowKey = TRUE;
  11569. }
  11570. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11577. }
  11578. else
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11581. }
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11583. isKnowKey = TRUE;
  11584. }
  11585. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11586. {
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11592. }
  11593. else
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11596. }
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11598. isKnowKey = TRUE;
  11599. }
  11600. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11601. {
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11607. }
  11608. else
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11611. }
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11613. isKnowKey = TRUE;
  11614. }
  11615. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11616. {
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11622. }
  11623. else
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11626. }
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11628. isKnowKey = TRUE;
  11629. }
  11630. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11631. {
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11637. }
  11638. else
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11641. }
  11642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11643. isKnowKey = TRUE;
  11644. }
  11645. #if 1
  11646. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11650. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11653. }
  11654. else
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11657. }
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11659. isKnowKey = TRUE;
  11660. }
  11661. #endif
  11662. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11666. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11669. }
  11670. else
  11671. {
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11673. }
  11674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11675. isKnowKey = TRUE;
  11676. }
  11677. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11678. {
  11679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11681. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11682. {
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11684. }
  11685. else
  11686. {
  11687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11688. }
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11690. isKnowKey = TRUE;
  11691. }
  11692. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11693. {
  11694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11696. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11699. }
  11700. else
  11701. {
  11702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11703. }
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11705. isKnowKey = TRUE;
  11706. }
  11707. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11708. {
  11709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11711. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11712. {
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11714. }
  11715. else
  11716. {
  11717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11718. }
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11720. isKnowKey = TRUE;
  11721. }
  11722. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11723. {
  11724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11726. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11727. {
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11729. }
  11730. else
  11731. {
  11732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11733. }
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11735. isKnowKey = TRUE;
  11736. }
  11737. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11738. {
  11739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11741. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11742. {
  11743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11744. }
  11745. else
  11746. {
  11747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11748. }
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11750. isKnowKey = TRUE;
  11751. }
  11752. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11753. {
  11754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11756. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11757. {
  11758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11759. }
  11760. else
  11761. {
  11762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11763. }
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11765. isKnowKey = TRUE;
  11766. }
  11767. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11768. {
  11769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11771. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11772. {
  11773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11774. }
  11775. else
  11776. {
  11777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11778. }
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11780. isKnowKey = TRUE;
  11781. }
  11782. //=========================================================
  11783. if(!isEmpty && !isKnowKey)
  11784. {
  11785. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11786. strcpy(unknownkey[UnknownKeynum], keyReq);
  11787. UnknownKeynum = UnknownKeynum + 1;
  11788. }
  11789. }
  11790. void processUnkownKey(void)
  11791. {
  11792. DEBUG_INFO("processUnkownKey...\n");
  11793. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11794. for(int index=0; index < UnknownKeynum; index++)
  11795. {
  11796. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11797. {
  11798. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11799. }
  11800. }
  11801. }
  11802. int setKeyValue(char *key, char *value)
  11803. {
  11804. int isSuccess = NotSupported;
  11805. int check_ascii=0;
  11806. char str[10]={0};
  11807. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11808. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11809. {
  11810. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11812. {
  11813. strcpy(str, (const char*)value);
  11814. for(int i = 0; str[i]; i++){
  11815. str[i] = tolower(str[i]);
  11816. }
  11817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11818. isSuccess = ConfigurationStatus_Accepted;
  11819. }
  11820. else
  11821. {
  11822. isSuccess = ConfigurationStatus_Rejected;
  11823. }
  11824. }
  11825. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11826. {
  11827. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11829. {
  11830. strcpy(str, (const char*)value);
  11831. for(int i = 0; str[i]; i++){
  11832. str[i] = tolower(str[i]);
  11833. }
  11834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11835. isSuccess = ConfigurationStatus_Accepted;
  11836. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11837. }
  11838. else
  11839. {
  11840. isSuccess = ConfigurationStatus_Rejected;
  11841. }
  11842. }
  11843. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11844. {
  11845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11846. {
  11847. strcpy(str, (const char*)value);
  11848. for(int i = 0; str[i]; i++)
  11849. {
  11850. str[i] = tolower(str[i]);
  11851. }
  11852. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11854. isSuccess = ConfigurationStatus_Accepted;
  11855. }
  11856. else
  11857. {
  11858. isSuccess = ConfigurationStatus_Rejected;
  11859. }
  11860. }
  11861. if(strcmp(key, "BlinkRepeat") == 0)
  11862. {
  11863. //Charger.BlinkRepeat = Integer.parseInt(value);
  11864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11865. {
  11866. check_ascii = value[0];
  11867. if( (check_ascii < 48) || (check_ascii > 57) )
  11868. {
  11869. isSuccess = ConfigurationStatus_Rejected;
  11870. }
  11871. else
  11872. {
  11873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11885. {
  11886. check_ascii = value[0];
  11887. if( (check_ascii < 48) || (check_ascii > 57) )
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. else
  11892. {
  11893. if((atoi(value) == 0) || (atoi(value) >= 10))
  11894. {
  11895. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11897. isSuccess = ConfigurationStatus_Accepted;
  11898. }
  11899. else
  11900. isSuccess = ConfigurationStatus_Rejected;
  11901. }
  11902. }
  11903. else
  11904. {
  11905. isSuccess = ConfigurationStatus_Rejected;
  11906. }
  11907. }
  11908. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11909. {
  11910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11911. {
  11912. check_ascii = value[0];
  11913. if( (check_ascii < 48) || (check_ascii > 57) )
  11914. {
  11915. isSuccess = ConfigurationStatus_Rejected;
  11916. }
  11917. else
  11918. {
  11919. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11921. isSuccess = ConfigurationStatus_Accepted;
  11922. }
  11923. }
  11924. else
  11925. {
  11926. isSuccess = ConfigurationStatus_Rejected;
  11927. }
  11928. }
  11929. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11930. {
  11931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11932. {
  11933. check_ascii = value[0];
  11934. if( (check_ascii < 48) || (check_ascii > 57) )
  11935. {
  11936. isSuccess = ConfigurationStatus_Rejected;
  11937. }
  11938. else
  11939. {
  11940. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11942. isSuccess = ConfigurationStatus_Accepted;
  11943. }
  11944. }
  11945. else
  11946. {
  11947. isSuccess = ConfigurationStatus_Rejected;
  11948. }
  11949. }
  11950. if(strcmp(key, "HeartbeatInterval") == 0)
  11951. {
  11952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11953. {
  11954. check_ascii = value[0];
  11955. if( (check_ascii < 48) || (check_ascii > 57) )
  11956. {
  11957. isSuccess = ConfigurationStatus_Rejected;
  11958. }
  11959. else
  11960. {
  11961. if((atoi(value) == 0) || (atoi(value) >= 10))
  11962. {
  11963. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11965. HeartBeatWaitTime = atoi(value);
  11966. isSuccess = ConfigurationStatus_Accepted;
  11967. }
  11968. else
  11969. {
  11970. isSuccess = ConfigurationStatus_Rejected;
  11971. }
  11972. }
  11973. }
  11974. else
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. }
  11979. if(strcmp(key, "LightIntensity") == 0)
  11980. {
  11981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].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[LightIntensity].ItemData, "%d", atoi(value) );
  11991. isSuccess = ConfigurationStatus_Accepted;
  11992. }
  11993. }
  11994. else
  11995. {
  11996. isSuccess = ConfigurationStatus_Rejected;
  11997. }
  11998. }
  11999. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12000. {
  12001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12002. {
  12003. strcpy(str, (const char*)value);
  12004. for(int i = 0; str[i]; i++)
  12005. {
  12006. str[i] = tolower(str[i]);
  12007. }
  12008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12009. isSuccess = ConfigurationStatus_Accepted;
  12010. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12011. }
  12012. else
  12013. {
  12014. isSuccess = ConfigurationStatus_Rejected;
  12015. }
  12016. }
  12017. if(strcmp(key, "LocalPreAuthorize") == 0)
  12018. {
  12019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12020. {
  12021. strcpy(str, (const char*)value);
  12022. for(int i = 0; str[i]; i++)
  12023. {
  12024. str[i] = tolower(str[i]);
  12025. }
  12026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12027. isSuccess = ConfigurationStatus_Accepted;
  12028. }
  12029. else
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. }
  12034. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12035. {
  12036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12037. {
  12038. check_ascii = value[0];
  12039. if( (check_ascii < 48) || (check_ascii > 57) )
  12040. {
  12041. isSuccess = ConfigurationStatus_Rejected;
  12042. }
  12043. else
  12044. {
  12045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12046. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12047. isSuccess = ConfigurationStatus_Accepted;
  12048. }
  12049. }
  12050. else
  12051. {
  12052. isSuccess = ConfigurationStatus_Rejected;
  12053. }
  12054. }
  12055. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12056. {
  12057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12058. {
  12059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12060. isSuccess = ConfigurationStatus_Accepted;
  12061. }
  12062. else
  12063. {
  12064. isSuccess = ConfigurationStatus_Rejected;
  12065. }
  12066. }
  12067. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12068. {
  12069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12070. {
  12071. check_ascii = value[0];
  12072. if( (check_ascii < 48) || (check_ascii > 57) )
  12073. {
  12074. isSuccess = ConfigurationStatus_Rejected;
  12075. }
  12076. else
  12077. {
  12078. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12089. {
  12090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12091. {
  12092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12093. isSuccess = ConfigurationStatus_Accepted;
  12094. }
  12095. else
  12096. {
  12097. isSuccess = ConfigurationStatus_Rejected;
  12098. }
  12099. }
  12100. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12101. {
  12102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12103. {
  12104. check_ascii = value[0];
  12105. if( (check_ascii < 48) || (check_ascii > 57) )
  12106. {
  12107. isSuccess = ConfigurationStatus_Rejected;
  12108. }
  12109. else
  12110. {
  12111. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12113. isSuccess = ConfigurationStatus_Accepted;
  12114. }
  12115. }
  12116. else
  12117. {
  12118. isSuccess = ConfigurationStatus_Rejected;
  12119. }
  12120. }
  12121. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12122. {
  12123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12124. {
  12125. check_ascii = value[0];
  12126. if( (check_ascii < 48) || (check_ascii > 57) )
  12127. {
  12128. isSuccess = ConfigurationStatus_Rejected;
  12129. }
  12130. else
  12131. {
  12132. if((atoi(value) == 0) || (atoi(value) >= 10))
  12133. {
  12134. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12136. isSuccess = ConfigurationStatus_Accepted;
  12137. }
  12138. else
  12139. {
  12140. isSuccess = ConfigurationStatus_Rejected;
  12141. }
  12142. }
  12143. }
  12144. else
  12145. {
  12146. isSuccess = ConfigurationStatus_Rejected;
  12147. }
  12148. }
  12149. if(strcmp(key, "MinimumStatusDuration") == 0)
  12150. {
  12151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12152. {
  12153. check_ascii = value[0];
  12154. if( (check_ascii < 48) || (check_ascii > 57) )
  12155. {
  12156. isSuccess = ConfigurationStatus_Rejected;
  12157. }
  12158. else
  12159. {
  12160. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12161. {
  12162. isSuccess = ConfigurationStatus_Rejected;
  12163. }
  12164. else
  12165. {
  12166. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12168. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12169. isSuccess = ConfigurationStatus_Accepted;
  12170. }
  12171. }
  12172. }
  12173. else
  12174. {
  12175. isSuccess = ConfigurationStatus_Rejected;
  12176. }
  12177. }
  12178. if(strcmp(key, "NumberOfConnectors") == 0)
  12179. {
  12180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12181. {
  12182. check_ascii = value[0];
  12183. if( (check_ascii < 48) || (check_ascii > 57) )
  12184. {
  12185. isSuccess = ConfigurationStatus_Rejected;
  12186. }
  12187. else
  12188. {
  12189. //Charger.ResetRetries = Integer.parseInt(value);
  12190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12191. isSuccess = ConfigurationStatus_Accepted;
  12192. }
  12193. }
  12194. else
  12195. {
  12196. isSuccess = ConfigurationStatus_Rejected;
  12197. }
  12198. }
  12199. if(strcmp(key, "ResetRetries") == 0)
  12200. {
  12201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12202. {
  12203. check_ascii = value[0];
  12204. if( (check_ascii < 48) || (check_ascii > 57) )
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. else
  12209. {
  12210. //Charger.ResetRetries = Integer.parseInt(value);
  12211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12212. isSuccess = ConfigurationStatus_Accepted;
  12213. }
  12214. }
  12215. else
  12216. {
  12217. isSuccess = ConfigurationStatus_Rejected;
  12218. }
  12219. }
  12220. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12221. {
  12222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12223. {
  12224. strcpy(str, (const char*)value);
  12225. for(int i = 0; str[i]; i++)
  12226. {
  12227. str[i] = tolower(str[i]);
  12228. }
  12229. if(strcmp(str, "notapplicable")== 0)
  12230. {
  12231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12232. isSuccess = ConfigurationStatus_Accepted;
  12233. }
  12234. else if(strcmp(str, "unknown")== 0)
  12235. {
  12236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12237. isSuccess = ConfigurationStatus_Accepted;
  12238. }
  12239. else if(strcmp(str, "rst")== 0)
  12240. {
  12241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12242. isSuccess = ConfigurationStatus_Accepted;
  12243. }
  12244. else if(strcmp(str, "rts")== 0)
  12245. {
  12246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12247. isSuccess = ConfigurationStatus_Accepted;
  12248. }
  12249. else if(strcmp(str, "srt")== 0)
  12250. {
  12251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12252. isSuccess = ConfigurationStatus_Accepted;
  12253. }
  12254. else if(strcmp(str, "str")== 0)
  12255. {
  12256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12257. isSuccess = ConfigurationStatus_Accepted;
  12258. }
  12259. else if(strcmp(str, "trs")== 0)
  12260. {
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. else if(strcmp(str, "tsr")== 0)
  12265. {
  12266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12267. isSuccess = ConfigurationStatus_Accepted;
  12268. }
  12269. else
  12270. {
  12271. isSuccess = ConfigurationStatus_Rejected;
  12272. }
  12273. }
  12274. else
  12275. {
  12276. isSuccess = ConfigurationStatus_Rejected;
  12277. }
  12278. }
  12279. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12280. {
  12281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12282. {
  12283. check_ascii = value[0];
  12284. if( (check_ascii < 48) || (check_ascii > 57) )
  12285. {
  12286. isSuccess = ConfigurationStatus_Rejected;
  12287. }
  12288. else
  12289. {
  12290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12291. isSuccess = ConfigurationStatus_Accepted;
  12292. }
  12293. }
  12294. else
  12295. {
  12296. isSuccess = ConfigurationStatus_Rejected;
  12297. }
  12298. }
  12299. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12300. {
  12301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12302. {
  12303. strcpy(str, (const char*)value);
  12304. for(int i = 0; str[i]; i++)
  12305. {
  12306. str[i] = tolower(str[i]);
  12307. }
  12308. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12310. isSuccess = ConfigurationStatus_Accepted;
  12311. }
  12312. else
  12313. {
  12314. isSuccess = ConfigurationStatus_Rejected;
  12315. }
  12316. }
  12317. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12318. {
  12319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12320. {
  12321. strcpy(str, (const char*)value);
  12322. for(int i = 0; str[i]; i++)
  12323. {
  12324. str[i] = tolower(str[i]);
  12325. }
  12326. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12328. isSuccess = ConfigurationStatus_Accepted;
  12329. }
  12330. else
  12331. {
  12332. isSuccess = ConfigurationStatus_Rejected;
  12333. }
  12334. }
  12335. if(strcmp(key, "StopTxnAlignedData") == 0)
  12336. {
  12337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12338. {
  12339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12340. isSuccess = ConfigurationStatus_Accepted;
  12341. }
  12342. else
  12343. {
  12344. isSuccess = ConfigurationStatus_Rejected;
  12345. }
  12346. }
  12347. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12348. {
  12349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12350. {
  12351. check_ascii = value[0];
  12352. if( (check_ascii < 48) || (check_ascii > 57) )
  12353. {
  12354. isSuccess = ConfigurationStatus_Rejected;
  12355. }
  12356. else
  12357. {
  12358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12359. isSuccess = ConfigurationStatus_Accepted;
  12360. }
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. if(strcmp(key, "StopTxnSampledData") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12370. {
  12371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12372. isSuccess = ConfigurationStatus_Accepted;
  12373. }
  12374. else
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. }
  12379. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12380. {
  12381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12382. {
  12383. check_ascii = value[0];
  12384. if( (check_ascii < 48) || (check_ascii > 57) )
  12385. {
  12386. isSuccess = ConfigurationStatus_Rejected;
  12387. }
  12388. else
  12389. {
  12390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12391. isSuccess = ConfigurationStatus_Accepted;
  12392. }
  12393. }
  12394. else
  12395. {
  12396. isSuccess = ConfigurationStatus_Rejected;
  12397. }
  12398. }
  12399. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12400. {
  12401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12402. {
  12403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12404. isSuccess = ConfigurationStatus_Accepted;
  12405. }
  12406. else
  12407. {
  12408. isSuccess = ConfigurationStatus_Rejected;
  12409. }
  12410. }
  12411. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12412. {
  12413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12414. {
  12415. check_ascii = value[0];
  12416. if( (check_ascii < 48) || (check_ascii > 57) )
  12417. {
  12418. isSuccess = ConfigurationStatus_Rejected;
  12419. }
  12420. else
  12421. {
  12422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12423. isSuccess = ConfigurationStatus_Accepted;
  12424. }
  12425. }
  12426. else
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. }
  12431. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12432. {
  12433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].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. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12444. TransactionMessageAttemptsValue = atoi(value);
  12445. isSuccess = ConfigurationStatus_Accepted;
  12446. }
  12447. }
  12448. else
  12449. {
  12450. isSuccess = ConfigurationStatus_Rejected;
  12451. }
  12452. }
  12453. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12454. {
  12455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12456. {
  12457. check_ascii = value[0];
  12458. if( (check_ascii < 48) || (check_ascii > 57) )
  12459. {
  12460. isSuccess = ConfigurationStatus_Rejected;
  12461. }
  12462. else
  12463. {
  12464. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12466. TransactionMessageRetryIntervalValue = atoi(value);
  12467. isSuccess = ConfigurationStatus_Accepted;
  12468. }
  12469. }
  12470. else
  12471. {
  12472. isSuccess = ConfigurationStatus_Rejected;
  12473. }
  12474. }
  12475. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12476. {
  12477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12478. {
  12479. strcpy(str, (const char*)value);
  12480. for(int i = 0; str[i]; i++)
  12481. {
  12482. str[i] = tolower(str[i]);
  12483. }
  12484. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12486. isSuccess = ConfigurationStatus_Accepted;
  12487. }
  12488. else
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. }
  12493. if(strcmp(key, "WebSocketPingInterval") == 0)
  12494. {
  12495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12496. {
  12497. check_ascii = value[0];
  12498. if( (check_ascii < 48) || (check_ascii > 57) )
  12499. {
  12500. isSuccess = ConfigurationStatus_Rejected;
  12501. }
  12502. else
  12503. {
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12505. isSuccess = ConfigurationStatus_Accepted;
  12506. }
  12507. }
  12508. else
  12509. {
  12510. isSuccess = ConfigurationStatus_Rejected;
  12511. }
  12512. }
  12513. #if 0
  12514. //For OCPP Test Case
  12515. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12516. {
  12517. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12518. {
  12519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12520. isSuccess = ConfigurationStatus_Accepted;
  12521. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12522. }
  12523. else
  12524. {
  12525. isSuccess = ConfigurationStatus_Rejected;
  12526. }
  12527. }
  12528. #endif
  12529. #if 1
  12530. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12531. {
  12532. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12533. {
  12534. strcpy(str, (const char*)value);
  12535. for(int i = 0; str[i]; i++)
  12536. {
  12537. str[i] = tolower(str[i]);
  12538. }
  12539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12540. isSuccess = ConfigurationStatus_Accepted;
  12541. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12542. }
  12543. else
  12544. {
  12545. isSuccess = ConfigurationStatus_Rejected;
  12546. }
  12547. }
  12548. #endif
  12549. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12550. {
  12551. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12552. {
  12553. check_ascii = value[0];
  12554. if( (check_ascii < 48) || (check_ascii > 57) )
  12555. {
  12556. isSuccess = ConfigurationStatus_Rejected;
  12557. }
  12558. else
  12559. {
  12560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12561. isSuccess = ConfigurationStatus_Accepted;
  12562. }
  12563. }
  12564. else
  12565. {
  12566. isSuccess = ConfigurationStatus_Rejected;
  12567. }
  12568. }
  12569. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12570. {
  12571. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12572. {
  12573. check_ascii = value[0];
  12574. if( (check_ascii < 48) || (check_ascii > 57) )
  12575. {
  12576. isSuccess = ConfigurationStatus_Rejected;
  12577. }
  12578. else
  12579. {
  12580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12581. isSuccess = ConfigurationStatus_Accepted;
  12582. }
  12583. }
  12584. else
  12585. {
  12586. isSuccess = ConfigurationStatus_Rejected;
  12587. }
  12588. }
  12589. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12590. {
  12591. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12592. {
  12593. strcpy(str, (const char*)value);
  12594. for(int i = 0; str[i]; i++)
  12595. {
  12596. str[i] = tolower(str[i]);
  12597. }
  12598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12599. isSuccess = ConfigurationStatus_Accepted;
  12600. }
  12601. else
  12602. {
  12603. isSuccess = ConfigurationStatus_Rejected;
  12604. }
  12605. }
  12606. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12607. {
  12608. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12609. {
  12610. check_ascii = value[0];
  12611. if( (check_ascii < 48) || (check_ascii > 57) )
  12612. {
  12613. isSuccess = ConfigurationStatus_Rejected;
  12614. }
  12615. else
  12616. {
  12617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12618. isSuccess = ConfigurationStatus_Accepted;
  12619. }
  12620. }
  12621. else
  12622. {
  12623. isSuccess = ConfigurationStatus_Rejected;
  12624. }
  12625. }
  12626. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12627. {
  12628. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12629. {
  12630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12631. isSuccess = ConfigurationStatus_Accepted;
  12632. }
  12633. else
  12634. {
  12635. isSuccess = ConfigurationStatus_Rejected;
  12636. }
  12637. }
  12638. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12639. {
  12640. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12641. {
  12642. check_ascii = value[0];
  12643. if( (check_ascii < 48) || (check_ascii > 57) )
  12644. {
  12645. isSuccess = ConfigurationStatus_Rejected;
  12646. }
  12647. else
  12648. {
  12649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12650. isSuccess = ConfigurationStatus_Accepted;
  12651. }
  12652. }
  12653. else
  12654. {
  12655. isSuccess = ConfigurationStatus_Rejected;
  12656. }
  12657. }
  12658. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12659. {
  12660. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12661. {
  12662. strcpy(str, (const char*)value);
  12663. for(int i = 0; str[i]; i++)
  12664. {
  12665. str[i] = tolower(str[i]);
  12666. }
  12667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12668. isSuccess = ConfigurationStatus_Accepted;
  12669. }
  12670. else
  12671. {
  12672. isSuccess = ConfigurationStatus_Rejected;
  12673. }
  12674. }
  12675. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12676. {
  12677. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12678. {
  12679. check_ascii = value[0];
  12680. if( (check_ascii < 48) || (check_ascii > 57) )
  12681. {
  12682. isSuccess = ConfigurationStatus_Rejected;
  12683. }
  12684. else
  12685. {
  12686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12687. isSuccess = ConfigurationStatus_Accepted;
  12688. }
  12689. }
  12690. else
  12691. {
  12692. isSuccess = ConfigurationStatus_Rejected;
  12693. }
  12694. }
  12695. return isSuccess;
  12696. }
  12697. int TransactionMessageAttemptsGet(void)
  12698. {
  12699. return TransactionMessageAttemptsValue;
  12700. }
  12701. int FirstHeartBeatResponse(void)
  12702. {
  12703. return FirstHeartBeat;
  12704. }
  12705. int TransactionMessageRetryIntervalGet(void)
  12706. {
  12707. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12708. }
  12709. int ReadHttpStatus(int sock)
  12710. {
  12711. //char c;
  12712. char buff[1024]="",*ptr=buff+1;
  12713. int bytes_received, status;
  12714. DEBUG_INFO("Begin Response ..\n");
  12715. while((bytes_received = recv(sock, ptr, 1, 0))){
  12716. if(bytes_received==-1){
  12717. perror("ReadHttpStatus");
  12718. exit(1);
  12719. }
  12720. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12721. ptr++;
  12722. }
  12723. *ptr=0;
  12724. ptr=buff+1;
  12725. sscanf(ptr,"%*s %d ", &status);
  12726. DEBUG_INFO("%s\n",ptr);
  12727. DEBUG_INFO("status=%d\n",status);
  12728. DEBUG_INFO("End Response ..\n");
  12729. return (bytes_received>0)?status:0;
  12730. }
  12731. //the only filed that it parsed is 'Content-Length'
  12732. int ParseHeader(int sock)
  12733. {
  12734. //char c;
  12735. char buff[1024]="",*ptr=buff+4;
  12736. int bytes_received;
  12737. DEBUG_INFO("Begin HEADER ..\n");
  12738. while((bytes_received = recv(sock, ptr, 1, 0))){
  12739. if(bytes_received==-1){
  12740. perror("Parse Header");
  12741. exit(1);
  12742. }
  12743. if(
  12744. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12745. (ptr[-1]=='\r') && (*ptr=='\n' )
  12746. ) break;
  12747. ptr++;
  12748. }
  12749. *ptr=0;
  12750. ptr=buff+4;
  12751. //printf("%s",ptr);
  12752. if(bytes_received){
  12753. ptr=strstr(ptr,"Content-Length:");
  12754. if(ptr){
  12755. sscanf(ptr,"%*s %d",&bytes_received);
  12756. }else
  12757. bytes_received=-1; //unknown size
  12758. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12759. }
  12760. DEBUG_INFO("End HEADER ..\n");
  12761. return bytes_received ;
  12762. }
  12763. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12764. {
  12765. char rmFileCmd[100]={0};
  12766. char FilePath[100]={0};
  12767. char ftpbuf[200];
  12768. int systemresult;
  12769. //DEBUG_INFO("filename=%s\n",filename);
  12770. //DEBUG_INFO("url=%s\n",url);
  12771. sprintf(FilePath,"/mnt/%s",filename);
  12772. if((access(FilePath,F_OK))!=-1)
  12773. {
  12774. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12775. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12776. system(rmFileCmd);
  12777. }
  12778. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12779. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12780. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12781. systemresult = system(ftpbuf);
  12782. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12783. if(systemresult != 0)
  12784. {
  12785. DEBUG_INFO("http DownLoad error!\n");
  12786. return FALSE;
  12787. }
  12788. return TRUE;
  12789. }
  12790. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12791. {
  12792. char rmFileCmd[100]={0};
  12793. char FilePath[100]={0};
  12794. char ftpbuf[200];
  12795. int systemresult;
  12796. //char temp[100];
  12797. sprintf(FilePath,"/mnt/%s",filename);
  12798. if((access(FilePath,F_OK))!=-1)
  12799. {
  12800. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12801. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12802. system(rmFileCmd);
  12803. }
  12804. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12805. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12806. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12807. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12808. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12809. systemresult = system(ftpbuf);
  12810. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12811. if(systemresult != 0)
  12812. {
  12813. printf("wget error!\n");
  12814. return FALSE;
  12815. }
  12816. return TRUE;
  12817. }
  12818. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12819. {
  12820. char rmFileCmd[100]={0};
  12821. char FilePath[100]={0};
  12822. char ftpbuf[200];
  12823. int systemresult;
  12824. //DEBUG_INFO("filename=%s\n",filename);
  12825. //DEBUG_INFO("url=%s\n",url);
  12826. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12827. if((access(FilePath,F_OK))!=-1)
  12828. {
  12829. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12830. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12831. system(rmFileCmd);
  12832. }
  12833. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12834. if(fp == NULL)
  12835. {
  12836. DEBUG_INFO("log is NULL\n");
  12837. return FALSE;
  12838. }
  12839. else
  12840. {
  12841. fprintf(fp, "%s\n", url);
  12842. fprintf(fp, "%s\n", filename);
  12843. fclose(fp);
  12844. }
  12845. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12846. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12847. systemresult = system(ftpbuf);
  12848. DEBUG_INFO("systemresult = %d\n",systemresult);
  12849. if(systemresult != 0)
  12850. {
  12851. DEBUG_INFO("http upload error!\n");
  12852. return FALSE;
  12853. }
  12854. return TRUE;
  12855. }
  12856. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12857. {
  12858. struct hostent* server;
  12859. char *IPbuffer;
  12860. char ftpbuf[200];
  12861. int systemresult;
  12862. // To retrieve host information
  12863. server = gethostbyname(location);
  12864. // To convert an Internet network
  12865. // address into ASCII string
  12866. IPbuffer = inet_ntoa(*((struct in_addr*)
  12867. server->h_addr_list[0]));
  12868. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12869. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12870. /* format : ftpput -u username -p passwd IP target source*/
  12871. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12872. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12873. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12874. systemresult = system(ftpbuf);
  12875. DEBUG_INFO("systemresult=%d\n",systemresult);
  12876. if(systemresult != 0)
  12877. {
  12878. DEBUG_INFO("ftpput error!\n");
  12879. return FALSE;
  12880. }
  12881. return TRUE;
  12882. }
  12883. /**
  12884. * Place the contents of the specified file into a memory buffer
  12885. *
  12886. * @param[in] filename The path and name of the file to read
  12887. * @param[out] filebuffer A pointer to the contents in memory
  12888. * @return status 0 success, 1 on failure
  12889. */
  12890. int get_file_contents(const char* filename, char** outbuffer) {
  12891. FILE* file = NULL;
  12892. long filesize;
  12893. const int blocksize = 1;
  12894. size_t readsize;
  12895. char* filebuffer;
  12896. // Open the file
  12897. file = fopen(filename, "r");
  12898. if (NULL == file)
  12899. {
  12900. printf("'%s' not opened\n", filename);
  12901. exit(EXIT_FAILURE);
  12902. }
  12903. // Determine the file size
  12904. fseek(file, 0, SEEK_END);
  12905. filesize = ftell(file);
  12906. rewind (file);
  12907. // Allocate memory for the file contents
  12908. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12909. *outbuffer = filebuffer;
  12910. if (filebuffer == NULL)
  12911. {
  12912. fputs ("malloc out-of-memory", stderr);
  12913. exit(EXIT_FAILURE);
  12914. }
  12915. // Read in the file
  12916. readsize = fread(filebuffer, blocksize, filesize, file);
  12917. if (readsize != filesize)
  12918. {
  12919. fputs ("didn't read file completely",stderr);
  12920. exit(EXIT_FAILURE);
  12921. }
  12922. // Clean exit
  12923. fclose(file);
  12924. return EXIT_SUCCESS;
  12925. }
  12926. static int selectSqlCount = 0;
  12927. static int callback(void *data, int argc, char **argv, char **azColName){
  12928. int i;
  12929. //printf("%s: ", (const char*)data);
  12930. selectSqlCount = argc;
  12931. for(i = 0; i<argc; i++){
  12932. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12933. }
  12934. //printf("\n");
  12935. return 0;
  12936. }
  12937. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12938. //int i;
  12939. //printf("%s:\n", (const char*)data);
  12940. localversion = argv[5] ? atoi(argv[5]) : 0;
  12941. //printf("localversion=%d\n", localversion);
  12942. return 0;
  12943. }
  12944. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12945. //int i;
  12946. //printf("%s:\n", (const char*)data);
  12947. //idTag
  12948. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12949. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12950. //parentIdTag
  12951. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12952. //expir_date
  12953. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12954. //status
  12955. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12956. //version
  12957. idTagQuery.listVersionInt = atoi(argv[5]);
  12958. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12959. return 0;
  12960. }
  12961. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12962. {
  12963. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12964. // printf("localversion=%d\n", localversion);
  12965. return 0;
  12966. }
  12967. //=========================================
  12968. // Sqlite3 related function
  12969. //=========================================
  12970. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12971. {
  12972. for (int i = 0; i < n_columns; i++)
  12973. {
  12974. DEBUG_INFO("%s/t", col_values[i]);
  12975. }
  12976. DEBUG_INFO("/n");
  12977. return 0;
  12978. }
  12979. void OCPP_getListVerion()
  12980. {
  12981. int rc = 0;
  12982. // const char* data = "Callback function called";
  12983. char sql[100];
  12984. char zErrMsg[100];
  12985. memset(sql, 0, 100);
  12986. memset(zErrMsg, 0, 100);
  12987. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12988. /* Execute SQL statement */
  12989. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12990. if( rc != SQLITE_OK )
  12991. {
  12992. DEBUG_INFO("SQL error: %s", zErrMsg);
  12993. }
  12994. }
  12995. void OCPP_getIdTag(char idTag[])
  12996. {
  12997. int rc = 0;
  12998. // const char* data = "Callback function called";
  12999. char sql[100];
  13000. char zErrMsg[100];
  13001. memset(sql, 0, 100);
  13002. memset(zErrMsg, 0, 100);
  13003. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13004. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13005. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13006. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13007. /* Execute SQL statement */
  13008. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13009. if( rc != SQLITE_OK )
  13010. {
  13011. DEBUG_INFO("SQL error: %s", zErrMsg);
  13012. }
  13013. //return ver;
  13014. }
  13015. void OCPP_get_TableAuthlocalAllData(void)
  13016. {
  13017. int rc = 0;
  13018. char sql[100];
  13019. char zErrMsg[100];
  13020. memset(sql, 0, 100);
  13021. memset(zErrMsg, 0, 100);
  13022. sprintf(sql,"select * from ocpp_auth_local ");
  13023. /* Execute SQL statement */
  13024. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13025. if( rc != SQLITE_OK )
  13026. {
  13027. DEBUG_INFO("SQL error: %s", zErrMsg);
  13028. }
  13029. //return ver;
  13030. }
  13031. int OCPP_cleanLocalList()
  13032. {
  13033. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13034. char *errMsg = 0;
  13035. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13036. if (SQLITE_OK != rc)
  13037. {
  13038. DEBUG_INFO("%s\n",errMsg);
  13039. return FALSE;
  13040. }
  13041. return TRUE;
  13042. }
  13043. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13044. {
  13045. int isSuccess = FALSE;
  13046. int ret = 0;
  13047. //const char* data = "Callback function called";
  13048. char sql[300];
  13049. char zErrMsg[200];
  13050. memset(sql, 0, 300);
  13051. memset(zErrMsg, 0, 200);
  13052. 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);
  13053. //* Execute SQL statement */
  13054. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13055. if( ret != SQLITE_OK )
  13056. {
  13057. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13058. return isSuccess;
  13059. }
  13060. memset(sql, 0, 300);
  13061. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13062. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13063. if( ret != SQLITE_OK )
  13064. {
  13065. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13066. return isSuccess;
  13067. }
  13068. isSuccess = TRUE;
  13069. return isSuccess;
  13070. }
  13071. void OCPP_deleteIdTag(char idTag[])
  13072. {
  13073. //int ver = 0;
  13074. //int isSuccess = FALSE;
  13075. int rc = 0;
  13076. char sql[100];
  13077. char zErrMsg[100];
  13078. memset(sql, 0, 100);
  13079. memset(zErrMsg, 0, 100);
  13080. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13081. //* Execute SQL statement */
  13082. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13083. if( rc != SQLITE_OK )
  13084. {
  13085. DEBUG_INFO("SQL error: %s", zErrMsg);
  13086. }
  13087. }
  13088. int GetOcppServerURL()
  13089. {
  13090. int result = FALSE;
  13091. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13092. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13093. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13094. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13095. {
  13096. #if 1
  13097. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13098. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13099. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13100. #endif
  13101. result = TRUE;
  13102. goto End;
  13103. }
  13104. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13105. {
  13106. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13107. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13108. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13109. result = TRUE;
  13110. goto End;
  13111. }
  13112. else
  13113. {
  13114. strcpy(OcppHost,"");
  13115. }
  13116. End:
  13117. return result;
  13118. }
  13119. int GetOcppPath()
  13120. {
  13121. int result = FALSE;
  13122. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13123. {
  13124. if(OcppTempPath == NULL)
  13125. {
  13126. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13127. }
  13128. else
  13129. {
  13130. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13131. }
  13132. result = TRUE;
  13133. goto End;
  13134. }
  13135. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13136. {
  13137. if(OcppTempPath == NULL)
  13138. {
  13139. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13140. }
  13141. else
  13142. {
  13143. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13144. }
  13145. result = TRUE;
  13146. goto End;
  13147. }
  13148. else
  13149. {
  13150. strcpy(OcppPath,"");
  13151. }
  13152. End:
  13153. return result;
  13154. }
  13155. int GetOcppPort()
  13156. {
  13157. return OcppPort;
  13158. }
  13159. int GetOcppConnStatus(void)
  13160. {
  13161. return ShmOCPP16Data->OcppConnStatus;
  13162. }
  13163. void SetOcppConnStatus(uint8_t status)
  13164. {
  13165. ShmOCPP16Data->OcppConnStatus = status;
  13166. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13167. }
  13168. int GetHeartBeatWithNOResponse(void)
  13169. {
  13170. return HeartBeatWithNOResponse;
  13171. }
  13172. void SetHeartBeatWithNOResponse(void)
  13173. {
  13174. HeartBeatWithNOResponse = 0;
  13175. }
  13176. void GetStartTransactionIdTag(int gun_index)
  13177. {
  13178. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13179. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13180. }
  13181. int GetTransactionId(int gunindex, unsigned char idTag[])
  13182. {
  13183. char ch;
  13184. FILE *fptr1;
  13185. int temptransactionId;
  13186. char str[100]={0};
  13187. temptransactionId = 0;
  13188. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13189. {
  13190. DEBUG_INFO("IdTag is empty.\n");
  13191. return temptransactionId;
  13192. }
  13193. /*------ Read the file ----------------*/
  13194. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13195. if (!fptr1)
  13196. {
  13197. DEBUG_INFO("QueueTransactionId file open error.\n");
  13198. //printf(" File not found or unable to open the input file!!\n");
  13199. return temptransactionId;
  13200. }
  13201. ch=fgetc(fptr1);
  13202. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13203. rewind(fptr1);
  13204. if(ch!=EOF)
  13205. {
  13206. // printf("%c",ch);
  13207. while (fgets(str, 100, fptr1) != NULL)
  13208. {
  13209. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13210. if(str[0]=='\0')
  13211. {
  13212. break;
  13213. }
  13214. char *revbuf[8] = {0}; //存放分割後的子字串
  13215. int num = 0;//分割後子字串的個數
  13216. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13217. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13218. {
  13219. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13220. {
  13221. temptransactionId = atoi(revbuf[2]);
  13222. break;
  13223. }
  13224. }
  13225. }
  13226. }
  13227. fclose(fptr1);
  13228. /*------- End of reading ---------------*/
  13229. return temptransactionId;
  13230. }
  13231. void SetTransactionIdZero(int transactionId)
  13232. {
  13233. char ch;
  13234. FILE *fptr1, *fptr2;
  13235. int temptransactionId = 0;
  13236. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13237. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13238. if (!fptr1)
  13239. {
  13240. //printf(" File not found or unable to open the input file!!\n");
  13241. return ;
  13242. }
  13243. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13244. if (!fptr2)
  13245. {
  13246. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13247. fclose(fptr1);
  13248. return ;
  13249. }
  13250. ch=fgetc(fptr1);
  13251. rewind(fptr1);
  13252. if(ch!=EOF)
  13253. {
  13254. // copy all contents to the temporary file except the specific line
  13255. while (fgets(str, 100, fptr1) != NULL)
  13256. {
  13257. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13258. if(str[0]=='\0')
  13259. {
  13260. break;
  13261. }
  13262. char *revbuf[8] = {0};
  13263. int num = 0;
  13264. strcpy(strtemp, str);
  13265. splitstring(str,",",revbuf,&num);
  13266. if(revbuf[2][0] != '\0')
  13267. {
  13268. temptransactionId = atoi(revbuf[2]);
  13269. if(transactionId != temptransactionId)
  13270. {
  13271. fprintf(fptr2, "%s\n", strtemp);
  13272. }
  13273. }
  13274. }
  13275. }
  13276. fclose(fptr1);
  13277. fclose(fptr2);
  13278. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13279. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13280. /*------ Read the file ----------------*/
  13281. }
  13282. int InternetDisconnect(void)
  13283. {
  13284. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13285. }
  13286. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13287. void storeTempStopTransaction(int gun_index)
  13288. {
  13289. char guid[37]={0};
  13290. int tempIndex = 0;
  13291. DEBUG_INFO("storeTempStopTransaction...\n");
  13292. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13293. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13294. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13295. if(gunType[gun_index] == 'J')
  13296. {
  13297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13298. {
  13299. tempIndex = ((gun_index==2) ? 1: 0);
  13300. }
  13301. else
  13302. {
  13303. tempIndex = gun_index;
  13304. }
  13305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13306. {
  13307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13308. {
  13309. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13310. }
  13311. }// END OF CHAdeMO_QUANTITY
  13312. }
  13313. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13314. {
  13315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13316. {
  13317. tempIndex = ((gun_index==2) ? 1: 0);
  13318. }
  13319. else
  13320. {
  13321. tempIndex = gun_index;
  13322. }
  13323. for (int index = 0; index < CCS_QUANTITY; index++)
  13324. {
  13325. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13326. {
  13327. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13328. }
  13329. }// END OF CCS_QUANTITY
  13330. }
  13331. else if(gunType[gun_index] == 'G')
  13332. {
  13333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13334. {
  13335. tempIndex = ((gun_index==2) ? 1: 0);
  13336. }
  13337. else
  13338. {
  13339. tempIndex = gun_index;
  13340. }
  13341. for (int index = 0; index < GB_QUANTITY; index++)
  13342. {
  13343. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13344. {
  13345. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13346. }
  13347. }// END OF GB_QUANTITY
  13348. }
  13349. else
  13350. {
  13351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13352. {
  13353. tempIndex = 2;
  13354. }
  13355. else
  13356. {
  13357. tempIndex = gun_index;
  13358. }
  13359. for (int index = 0; index < AC_QUANTITY; index++)
  13360. {
  13361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13362. {
  13363. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13364. }
  13365. }// END OF AC_QUANTITY
  13366. }
  13367. //Stop Transaction Time
  13368. struct timeval tmnow;
  13369. struct tm *tm;
  13370. char buf[28];//, usec_buf[6];
  13371. gettimeofday(&tmnow, NULL);
  13372. time_t t;
  13373. t = time(NULL);
  13374. /*UTC time and date*/
  13375. tm = gmtime(&t);
  13376. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13378. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13380. random_uuid(guid);
  13381. /***********************************transactionData******************************************************/
  13382. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13384. //=================================
  13385. //1. Transaction_Begin
  13386. //=================================
  13387. //============================== Energy.Active.Import.Interval ===========================================
  13388. //idx_sample=0;
  13389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13392. 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*/]);
  13393. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13394. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13395. {
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13397. }
  13398. else
  13399. {
  13400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13401. }
  13402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13404. //=================================
  13405. //2. Transaction_End
  13406. //=================================
  13407. //2.1====================================== Current.Import L1 ==============================================
  13408. //idx_sample=1;
  13409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13410. if(gunType[gun_index] == 'J')
  13411. {
  13412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13413. {
  13414. tempIndex = ((gun_index==2) ? 1: 0);
  13415. }
  13416. else
  13417. {
  13418. tempIndex = gun_index;
  13419. }
  13420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13421. {
  13422. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13423. {
  13424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13425. }
  13426. }// End of for CHAdeMO_QUANTITY
  13427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13428. }
  13429. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13430. {
  13431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13432. {
  13433. tempIndex = ((gun_index==2) ? 1: 0);
  13434. }
  13435. else
  13436. {
  13437. tempIndex = gun_index;
  13438. }
  13439. for (int index = 0; index < CCS_QUANTITY; index++)
  13440. {
  13441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13442. {
  13443. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13444. }
  13445. }// End of for CCS_QUANTITY
  13446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13447. }
  13448. else if(gunType[gun_index] == 'G')
  13449. {
  13450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13451. {
  13452. tempIndex = ((gun_index==2) ? 1: 0);
  13453. }
  13454. else
  13455. {
  13456. tempIndex = gun_index;
  13457. }
  13458. for (int index = 0; index < GB_QUANTITY; index++)
  13459. {
  13460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13461. {
  13462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13463. }
  13464. }// End of for GB_QUANTITY
  13465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13466. }
  13467. else
  13468. {
  13469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13470. {
  13471. tempIndex = 2;
  13472. }
  13473. else
  13474. {
  13475. tempIndex = gun_index;
  13476. }
  13477. for (int index = 0; index < AC_QUANTITY; index++)
  13478. {
  13479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13482. }
  13483. }// End of for AC_QUANTITY
  13484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13485. }
  13486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13489. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13492. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13493. //idx_sample=2;
  13494. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13495. if(gunType[gun_index] == 'J')
  13496. {
  13497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13498. {
  13499. tempIndex = ((gun_index==2) ? 1: 0);
  13500. }
  13501. else
  13502. {
  13503. tempIndex = gun_index;
  13504. }
  13505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13506. {
  13507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13508. {
  13509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13510. }
  13511. }// END OF CHAdeMO_QUANTITY
  13512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13513. }
  13514. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13515. {
  13516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13517. {
  13518. tempIndex = ((gun_index==2) ? 1: 0);
  13519. }
  13520. else
  13521. {
  13522. tempIndex = gun_index;
  13523. }
  13524. for (int index = 0; index < CCS_QUANTITY; index++)
  13525. {
  13526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13527. {
  13528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13529. }
  13530. }// END OF CCS_QUANTITY
  13531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13532. }
  13533. else if(gunType[gun_index] == 'G')
  13534. {
  13535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13536. {
  13537. tempIndex = ((gun_index==2) ? 1: 0);
  13538. }
  13539. else
  13540. {
  13541. tempIndex = gun_index;
  13542. }
  13543. for (int index = 0; index < GB_QUANTITY; index++)
  13544. {
  13545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13546. {
  13547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13548. }
  13549. }// END OF GB_QUANTITY
  13550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13551. }
  13552. else
  13553. {
  13554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13555. {
  13556. tempIndex = 2;
  13557. }
  13558. else
  13559. {
  13560. tempIndex = gun_index;
  13561. }
  13562. for (int index = 0; index < AC_QUANTITY; index++)
  13563. {
  13564. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13565. {
  13566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13567. }
  13568. }// END OF AC_QUANTITY
  13569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13570. }
  13571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13574. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13577. //2.3====================================== Power.Active.Export =========================================
  13578. //idx_sample=3;
  13579. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13580. if(gunType[gun_index] == 'J')
  13581. {
  13582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13583. {
  13584. tempIndex = ((gun_index==2) ? 1: 0);
  13585. }
  13586. else
  13587. {
  13588. tempIndex = gun_index;
  13589. }
  13590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13591. {
  13592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13593. {
  13594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13595. }
  13596. } // End for CHAdeMO_QUANTITY
  13597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13598. }
  13599. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13600. {
  13601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13602. {
  13603. tempIndex = ((gun_index==2) ? 1: 0);
  13604. }
  13605. else
  13606. {
  13607. tempIndex = gun_index;
  13608. }
  13609. for (int index = 0; index < CCS_QUANTITY; index++)
  13610. {
  13611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13612. {
  13613. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13614. }
  13615. } // END for CCS_QUANTITY
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13617. }
  13618. else if(gunType[gun_index] == 'G')
  13619. {
  13620. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13621. {
  13622. tempIndex = ((gun_index==2) ? 1: 0);
  13623. }
  13624. else
  13625. {
  13626. tempIndex = gun_index;
  13627. }
  13628. for (int index = 0; index < GB_QUANTITY; index++)
  13629. {
  13630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13631. {
  13632. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13633. }
  13634. }// END for GB_QUANTITY
  13635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13636. }
  13637. else
  13638. {
  13639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13640. {
  13641. tempIndex = 2;
  13642. }
  13643. else
  13644. {
  13645. tempIndex = gun_index;
  13646. }
  13647. for (int index = 0; index < AC_QUANTITY; index++)
  13648. {
  13649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13650. {
  13651. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13652. }
  13653. } // END for AC_QUANTITY
  13654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13655. }
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13659. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13662. //2.4====================================== Voltage L1 ====================================================
  13663. //idx_sample=4;
  13664. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13665. if(gunType[gun_index] == 'J')
  13666. {
  13667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13668. {
  13669. tempIndex = ((gun_index==2) ? 1: 0);
  13670. }
  13671. else
  13672. {
  13673. tempIndex = gun_index;
  13674. }
  13675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13676. {
  13677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13678. {
  13679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13680. }
  13681. } // END OF FOR CHAdeMO_QUANTITY
  13682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13683. }
  13684. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13685. {
  13686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13687. {
  13688. tempIndex = ((gun_index==2) ? 1: 0);
  13689. }
  13690. else
  13691. {
  13692. tempIndex = gun_index;
  13693. }
  13694. for (int index = 0; index < CCS_QUANTITY; index++)
  13695. {
  13696. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13697. {
  13698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13699. }
  13700. } // END OF FOR CCS_QUANTITY
  13701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13702. }
  13703. else if(gunType[gun_index] == 'G')
  13704. {
  13705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13706. {
  13707. tempIndex = ((gun_index==2) ? 1: 0);
  13708. }
  13709. else
  13710. {
  13711. tempIndex = gun_index;
  13712. }
  13713. for (int index = 0; index < GB_QUANTITY; index++)
  13714. {
  13715. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13716. {
  13717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13718. }
  13719. } // END OF FOR GB_QUANTITY
  13720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13721. }
  13722. else
  13723. {
  13724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13725. {
  13726. tempIndex = 2;
  13727. }
  13728. else
  13729. {
  13730. tempIndex = gun_index;
  13731. }
  13732. for (int index = 0; index < AC_QUANTITY; index++)
  13733. {
  13734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13735. {
  13736. 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
  13737. }
  13738. } // END OF FOR AC_QUANTITY
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13740. }
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13744. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13747. //2.5============================================== SoC =========================================================
  13748. //idx_sample=5;
  13749. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13750. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13751. {
  13752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13753. {
  13754. tempIndex = ((gun_index==2) ? 1: 0);
  13755. }
  13756. else
  13757. {
  13758. tempIndex = gun_index;
  13759. }
  13760. if(gunType[gun_index] == 'J')
  13761. {
  13762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13763. {
  13764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13765. {
  13766. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13767. }
  13768. }
  13769. }
  13770. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13771. {
  13772. for (int index = 0; index < CCS_QUANTITY; index++)
  13773. {
  13774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13775. {
  13776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13777. }
  13778. }
  13779. }
  13780. else if(gunType[gun_index] == 'G')
  13781. {
  13782. for (int index = 0; index < GB_QUANTITY; index++)
  13783. {
  13784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13785. {
  13786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13787. }
  13788. }
  13789. }
  13790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13796. } // END FOR DC CASE
  13797. //2.6====================================== Current.Import L2 ==============================================
  13798. // idx_sample=6;
  13799. // AC 3 phase L2 current
  13800. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13801. {
  13802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13803. {
  13804. tempIndex = 2;
  13805. }
  13806. else
  13807. {
  13808. tempIndex = gun_index;
  13809. }
  13810. for (int index = 0; index < AC_QUANTITY; index++)
  13811. {
  13812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13813. {
  13814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13815. }
  13816. }// End of for AC_QUANTITY
  13817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13818. }
  13819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13824. //2.7====================================== Current.Import L3 ==============================================
  13825. // idx_sample=7;
  13826. // AC 3 phase L3 current
  13827. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13828. {
  13829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13830. {
  13831. tempIndex = 2;
  13832. }
  13833. else
  13834. {
  13835. tempIndex = gun_index;
  13836. }
  13837. for (int index = 0; index < AC_QUANTITY; index++)
  13838. {
  13839. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13840. {
  13841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13842. }
  13843. }// End of for AC_QUANTITY
  13844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13845. }
  13846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13851. //2.9====================================== Voltage L2 ====================================================
  13852. //idx_sample=8;
  13853. // AC 3 phase L2 volatge
  13854. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13855. {
  13856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13857. {
  13858. tempIndex = 2;
  13859. }
  13860. else
  13861. {
  13862. tempIndex = gun_index;
  13863. }
  13864. for (int index = 0; index < AC_QUANTITY; index++)
  13865. {
  13866. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13867. {
  13868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  13869. }
  13870. } // END OF FOR AC_QUANTITY
  13871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13872. }
  13873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13878. //2.10====================================== Voltage L3 ====================================================
  13879. //idx_sample=9;
  13880. // AC 3 phase L3 volatge
  13881. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13882. {
  13883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13884. {
  13885. tempIndex = 2;
  13886. }
  13887. else
  13888. {
  13889. tempIndex = gun_index;
  13890. }
  13891. for (int index = 0; index < AC_QUANTITY; index++)
  13892. {
  13893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13894. {
  13895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  13896. }
  13897. } // END OF FOR AC_QUANTITY
  13898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13899. }
  13900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13905. //======================================== Message create ==============================================
  13906. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13907. {
  13908. 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\"}]}]}]"
  13909. ,gun_index+1
  13910. ,MESSAGE_TYPE_CALL
  13911. ,guid
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13916. ,"PowerLoss"
  13917. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13960. );
  13961. }
  13962. else
  13963. {
  13964. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13965. {
  13966. 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\"}]}]}]"
  13967. ,gun_index+1
  13968. ,MESSAGE_TYPE_CALL
  13969. ,guid
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13971. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13972. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13974. ,"PowerLoss"
  13975. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14011. );
  14012. }
  14013. else
  14014. {
  14015. 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\"},{\"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\"}]}]}]"
  14016. ,gun_index+1
  14017. ,MESSAGE_TYPE_CALL
  14018. ,guid
  14019. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14020. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14021. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14023. ,"PowerLoss"
  14024. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14046. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14047. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14048. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14049. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14050. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14088. );
  14089. }
  14090. }
  14091. // Check File "TempStopTransaction" Exist
  14092. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14093. {
  14094. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14095. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14096. }
  14097. else
  14098. {
  14099. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14100. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14101. if(log == NULL)
  14102. {
  14103. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14104. return ;
  14105. }
  14106. else
  14107. {
  14108. fclose(log);
  14109. }
  14110. }
  14111. //Add TempStopTransaction | Update TempStopTransaction
  14112. // open file for writing
  14113. FILE *outfile;
  14114. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14115. //DEBUG_INFO("data = %s\n", queuedata);
  14116. fputs(queuedata, outfile);
  14117. fputs("\n", outfile);
  14118. fclose (outfile);
  14119. }
  14120. void checkTempStopTransaction(int gun_index)
  14121. {
  14122. FILE *fptr1;
  14123. char ch;
  14124. char str[QUEUE_MESSAGE_LENGTH]={0};
  14125. char guid[37]={0};
  14126. char tempdata[65]={0};
  14127. char connectorStr[2]={0};
  14128. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14129. //TempStopTransaction格式: 槍號,StopTransaction封包
  14130. if (!fptr1)
  14131. {
  14132. //printf(" File not found or unable to open the input file!!\n");
  14133. return ;
  14134. }
  14135. ch=fgetc(fptr1);
  14136. //printf(" Now the content of the file %s is : \n",fname);
  14137. rewind(fptr1);
  14138. if(ch!=EOF)
  14139. {
  14140. // copy all contents to the temporary file except the specific line
  14141. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14142. {
  14143. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14144. if(str[0]=='\0')
  14145. {
  14146. break;
  14147. }
  14148. //TempStopTransaction格式: 槍號,StopTransaction封包
  14149. strncpy(connectorStr, str, 1);
  14150. if(atoi(connectorStr) != (gun_index+1))
  14151. {
  14152. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14153. return ;
  14154. }
  14155. //random_uuid(guid);
  14156. strncpy(guid, str+6, 36); //copy guid
  14157. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14158. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14159. {
  14160. DEBUG_INFO("StopTransaction mapitem pass\n");
  14161. }
  14162. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14163. memset(str,0,ARRAY_SIZE(str));
  14164. }
  14165. }
  14166. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14167. fclose(fptr1);
  14168. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14169. }
  14170. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14171. {
  14172. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14173. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14174. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14175. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14176. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14177. }
  14178. int GetWebSocketPingInterval(void)
  14179. {
  14180. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14181. }
  14182. int GetServerSign(void)
  14183. {
  14184. return server_sign;
  14185. }
  14186. void SetServerSign(int value)
  14187. {
  14188. server_sign = value;
  14189. }
  14190. int GetBootNotificationInterval(void)
  14191. {
  14192. return BootNotificationInterval;
  14193. }
  14194. int GetInternetConn(void)
  14195. {
  14196. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14197. }
  14198. void InitialSystemValue(void)
  14199. {
  14200. int connectorIndex = 0;
  14201. //int valueASCII = 0;
  14202. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14203. gunTotalNumber=0;
  14204. SystemInitial = 0;
  14205. localversion=0;
  14206. BootNotificationInterval = 0;
  14207. authorizeRetryTimes = 0;
  14208. GunStatusInterval = 10;
  14209. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14210. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14211. //Hear Beat
  14212. HeartBeatWithNOResponse = 0;
  14213. HeartBeatCountPerHour = 0;
  14214. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14215. FirstHeartBeat = 0;
  14216. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14217. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14218. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14219. memset(statusModeChage, 0, sizeof(statusModeChage));
  14220. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  14221. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  14222. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  14223. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  14224. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  14225. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  14226. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  14227. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  14228. memset(gunType, 0, sizeof(gunType));
  14229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14230. {
  14231. //check connector / socket type (index: 8, 9, 10)
  14232. for(int index=7; index <10 ; index++)
  14233. {
  14234. if(index != 8)
  14235. {
  14236. // DC Connector
  14237. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14238. {
  14239. SystemInitial = SystemInitial + 1;
  14240. gunTotalNumber = gunTotalNumber + 1;
  14241. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14242. connectorIndex = connectorIndex + 1;
  14243. }
  14244. }
  14245. else
  14246. {
  14247. // AC Connector
  14248. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14249. {
  14250. SystemInitial = SystemInitial + 1;
  14251. gunTotalNumber = gunTotalNumber + 1;
  14252. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14253. connectorIndex = connectorIndex + 1;
  14254. }
  14255. }
  14256. }
  14257. //DEBUG_INFO("DC ...\n");
  14258. }
  14259. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14260. {
  14261. //check connector / socket type (index: 8, 9, 10)
  14262. for(int index=7; index <10 ; index++)
  14263. {
  14264. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14265. {
  14266. SystemInitial = SystemInitial + 1;
  14267. gunTotalNumber = gunTotalNumber + 1;
  14268. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14269. connectorIndex = connectorIndex + 1;
  14270. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14271. }
  14272. }
  14273. }
  14274. //Status && ConnectorPlugIn Setting
  14275. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14276. {
  14277. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14278. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14279. }
  14280. for (int index = 0; index < CCS_QUANTITY; index++)
  14281. {
  14282. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14283. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14284. }
  14285. for (int index = 0; index < GB_QUANTITY; index++)
  14286. {
  14287. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14288. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14289. }
  14290. for (int index = 0; index < AC_QUANTITY; index++)
  14291. {
  14292. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14293. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14294. }
  14295. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14296. {
  14297. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14298. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14299. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14300. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14301. }
  14302. // Charger PRE_SYS_MODE
  14303. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  14304. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14305. clientTime.Heartbeat=time((time_t*)NULL);
  14306. sleep(1);
  14307. }
  14308. void LWS_Send(char * str)
  14309. {
  14310. //=====================================================
  14311. // Check InternetConn 0: disconnected, 1: connected
  14312. //====================================================
  14313. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14314. {
  14315. DEBUG_INFO("offline now !!!\n");
  14316. return;
  14317. }
  14318. pthread_mutex_lock(&lock_send);
  14319. memset(SendBuffer, 0, SendBufLen);
  14320. sprintf((char *)SendBuffer, "%s", str);
  14321. pthread_mutex_unlock(&lock_send);
  14322. lws_callback_on_writable(wsi_client);
  14323. lws_service(context, 0);
  14324. //sleep(1);
  14325. }