MessageHandler.c 668 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471
  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. for(uint8_t idx=0;idx<json_object_array_length(data);idx++)
  6295. {
  6296. ShmSysConfigAndInfo->SysConfig.LedInfo[json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Id"))].Intensity = json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Intensity"));
  6297. ShmSysConfigAndInfo->SysConfig.LedInfo[json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Id"))].Red = json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Red"));
  6298. ShmSysConfigAndInfo->SysConfig.LedInfo[json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Id"))].Green = json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Green"));
  6299. ShmSysConfigAndInfo->SysConfig.LedInfo[json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Id"))].Blue = json_object_get_int(json_object_object_get(json_object_array_get_idx(data, idx), "Blue"));
  6300. }
  6301. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6302. }
  6303. else
  6304. {
  6305. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6306. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6307. }
  6308. json_object_put(data);
  6309. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6310. }
  6311. else
  6312. {
  6313. // Can not find valid message id
  6314. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6315. }
  6316. }
  6317. else
  6318. {
  6319. // Payload is null
  6320. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6321. }
  6322. LWS_Send(message);
  6323. return result;
  6324. }
  6325. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6326. {
  6327. mtrace();
  6328. int result = FAIL;
  6329. int connectorIdInt, durationInt;
  6330. char chargingRateUnitStr[4]={0};
  6331. char comfirmstr[20];
  6332. int confirmPeriods = 0;
  6333. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6334. json_object *GetCompositeSchedule;
  6335. GetCompositeSchedule = json_tokener_parse(payload);
  6336. if(!is_error(GetCompositeSchedule))
  6337. {
  6338. // Required data
  6339. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6340. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6341. // Optional data
  6342. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6343. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6344. }
  6345. json_object_put(GetCompositeSchedule);
  6346. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6347. if((connectorIdInt == 0) ||
  6348. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6349. {
  6350. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6351. struct StructChargingProfile tmpProfile[1];
  6352. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6353. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6354. {
  6355. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6356. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6357. }
  6358. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6359. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6360. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6361. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6362. {
  6363. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6364. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6365. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6366. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6367. {
  6368. confirmPeriods = idx;
  6369. break;
  6370. }
  6371. }
  6372. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6373. }
  6374. else
  6375. {
  6376. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6377. }
  6378. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6379. return result;
  6380. }
  6381. int handleGetConfigurationRequest(char *uuid, char *payload)
  6382. {
  6383. mtrace();
  6384. int result = FAIL;
  6385. int MaxKeySupported = 0;
  6386. int n_keys = 0;
  6387. char requestKey[43][50]={0};
  6388. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6389. json_object *GetConfiguration;
  6390. GetConfiguration = json_tokener_parse(payload);
  6391. if(!is_error(GetConfiguration))
  6392. {
  6393. // Optional data
  6394. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6395. {
  6396. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6397. {
  6398. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6399. n_keys = idx + 1;
  6400. }
  6401. }
  6402. }
  6403. json_object_put(GetConfiguration);
  6404. UnknownKeynum = 0;
  6405. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6406. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6407. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6408. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6409. if(n_keys != 0)
  6410. {
  6411. for(int i=0;i<n_keys;i++)
  6412. {
  6413. getKeyValue(requestKey[i]);
  6414. }
  6415. }
  6416. else
  6417. {
  6418. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6419. getKeyValue("");
  6420. }
  6421. processUnkownKey();
  6422. sendGetConfigurationConfirmation(uuid);
  6423. return result;
  6424. }
  6425. static char fnamePlusPath[100]={0};
  6426. static char fnamePWithNoPath[60]={0};
  6427. void checkUploadLog(void)
  6428. {
  6429. FILE *fp;
  6430. /* Open the command for reading. */
  6431. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6432. if (fp == NULL) {
  6433. printf("Failed to run command\n" );
  6434. exit(1);
  6435. }
  6436. int ftppathlen = 0;
  6437. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6438. int i = 0;
  6439. /* Read the output a line at a time - output it. */
  6440. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6441. if(i==0)
  6442. {
  6443. ftppathlen = strlen(fnamePlusPath);
  6444. printf("%s\n", fnamePlusPath);
  6445. fnamePlusPath[ftppathlen]='\0';
  6446. break;
  6447. }
  6448. i= i+1;
  6449. }
  6450. /* close */
  6451. pclose(fp);
  6452. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6453. {
  6454. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6455. {
  6456. fnamePlusPath[k]='\0';
  6457. }
  6458. }
  6459. i=1;
  6460. //char fname[60]={0};
  6461. while(i < ftppathlen)
  6462. {
  6463. int len=ftppathlen-i;
  6464. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6465. {
  6466. printf("compare '/' all right\n");
  6467. break;
  6468. }
  6469. i=i+1;
  6470. }
  6471. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6472. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6473. fnamePWithNoPath[i+1] = '\0';
  6474. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6475. {
  6476. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6477. {
  6478. fnamePWithNoPath[j]='\0';
  6479. }
  6480. }
  6481. FILE* fp1 = fopen(fnamePlusPath, "r");
  6482. if (fp1)
  6483. {
  6484. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6485. // file exists
  6486. fclose(fp1);
  6487. }
  6488. else
  6489. {
  6490. // file doesn't exist
  6491. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6492. }
  6493. }
  6494. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6495. {
  6496. mtrace();
  6497. int result = FAIL;
  6498. char cmdBuf[512];
  6499. char fName[258];
  6500. time_t CurrentTime;
  6501. struct tm *tm;
  6502. system("/usr/bin/run_tmate_restart.sh");
  6503. pthread_t th_Status;
  6504. CurrentTime = time(NULL);
  6505. tm = localtime(&CurrentTime);
  6506. 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);
  6507. sendGetDiagnosticsConfirmation(uuid, fName);
  6508. system("exec /root/logPackTools 'log' 6");
  6509. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6510. system(cmdBuf);
  6511. checkUploadLog();
  6512. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6513. return result;
  6514. }
  6515. void* GetDiagnosticsProcess(void* data)
  6516. {
  6517. pthread_detach(pthread_self());
  6518. mtrace();
  6519. int retriesInt=0, retryIntervalInt=0;
  6520. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6521. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6522. 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};
  6523. int port=0;
  6524. char sstr[260]={ 0 };
  6525. int c = 0;
  6526. char *loc;
  6527. int isSuccess = FALSE;
  6528. char ftpbuf[200]={0};
  6529. char * pch;
  6530. char str[300]={ 0 };
  6531. strcpy(str,(const char*)data);
  6532. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6533. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6534. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6535. //****************location*******************/
  6536. c = 0;
  6537. memset(sstr ,0, ARRAY_SIZE(sstr));
  6538. loc = strstr(str, "location");
  6539. while (loc[3+strlen("location")+c] != '\"')
  6540. {
  6541. sstr[c] = loc[3+strlen("location")+c];
  6542. c++;
  6543. }
  6544. sstr[c] = '\0';
  6545. strcpy(locationstr,sstr);
  6546. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6547. if(strcmp(locationstr,"")==0)
  6548. {
  6549. DEBUG_INFO("location is <Empty>!\n");
  6550. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6551. goto end;
  6552. }
  6553. //****************retries*******************/
  6554. c = 0;
  6555. loc = strstr(str, "retries");
  6556. if(loc == NULL)
  6557. {
  6558. retriesIsNULL = TRUE;
  6559. }
  6560. else
  6561. {
  6562. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6563. {
  6564. sstr[c] = loc[strlen("retries")+2+c];
  6565. c++;
  6566. }
  6567. sstr[c] = '\0';
  6568. retriesInt = atoi(sstr);
  6569. }
  6570. if(retriesIsNULL == TRUE)
  6571. {
  6572. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6573. }
  6574. //****************retryInterval*******************/
  6575. c = 0;
  6576. loc = strstr(str, "retryInterval");
  6577. if(loc == NULL)
  6578. {
  6579. retryIntervalIsNULL = TRUE;
  6580. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6581. }
  6582. else
  6583. {
  6584. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6585. {
  6586. sstr[c] = loc[strlen("retryInterval")+2+c];
  6587. c++;
  6588. }
  6589. sstr[c] = '\0';
  6590. retryIntervalInt = atoi(sstr);
  6591. }
  6592. //****************startTime*******************/
  6593. c = 0;
  6594. memset(sstr ,0, ARRAY_SIZE(sstr));
  6595. loc = strstr(str, "startTime");
  6596. if(loc == NULL)
  6597. {
  6598. startTimeIsNULL = TRUE;
  6599. }
  6600. else
  6601. {
  6602. while (loc[3+strlen("startTime")+c] != '\"')
  6603. {
  6604. sstr[c] = loc[3+strlen("startTime")+c];
  6605. c++;
  6606. }
  6607. sstr[c] = '\0';
  6608. strcpy(startTimestr,sstr);
  6609. }
  6610. //****************stopTime*******************/
  6611. c = 0;
  6612. memset(sstr ,0, ARRAY_SIZE(sstr));
  6613. loc = strstr(str, "stopTime");
  6614. if(loc == NULL)
  6615. {
  6616. stopTimeIsNULL = TRUE;
  6617. }
  6618. else
  6619. {
  6620. while (loc[3+strlen("stopTime")+c] != '\"')
  6621. {
  6622. sstr[c] = loc[3+strlen("stopTime")+c];
  6623. c++;
  6624. }
  6625. sstr[c] = '\0';
  6626. strcpy(stopTimestr,sstr);
  6627. }
  6628. memset(protocol, 0, ARRAY_SIZE(protocol));
  6629. memset(user, 0, ARRAY_SIZE(user) );
  6630. memset(password, 0, ARRAY_SIZE(password));
  6631. memset(host, 0, ARRAY_SIZE(host));
  6632. memset(path, 0, ARRAY_SIZE(path));
  6633. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6634. memset(host1, 0, ARRAY_SIZE(host1));
  6635. memset(path1, 0, ARRAY_SIZE(path1));
  6636. /*location: ftp://user:password@host:port/path*/
  6637. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6638. if((access(fnamePlusPath,F_OK))!=-1)
  6639. {
  6640. DEBUG_INFO("fnamePlusPath exist.\n");
  6641. }
  6642. else
  6643. {
  6644. DEBUG_INFO("fnamePlusPath not exist!\n");
  6645. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6646. goto end;
  6647. }
  6648. pch=strchr(locationstr,'@');
  6649. if(pch==NULL)
  6650. {
  6651. sscanf(locationstr,
  6652. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6653. protocol, host, &port, path);
  6654. strcpy(user,"anonymous");
  6655. strcpy(password,"");
  6656. }
  6657. else
  6658. {
  6659. //DEBUG_INFO("pch=%s\n", pch);
  6660. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6661. protocol, user, password, host, &port, path);
  6662. }
  6663. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6664. {
  6665. DEBUG_INFO("protocol is not ftp/http ! \n");
  6666. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6667. goto end;
  6668. }
  6669. if(strncmp(locationstr,"http", 4) == 0)
  6670. {
  6671. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6672. sprintf(ftppath,"/%s", path);
  6673. do{
  6674. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6675. sleep(retryIntervalInt);
  6676. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6677. if(!isSuccess)
  6678. {
  6679. DEBUG_INFO("Diagnostics fail.\n");
  6680. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6681. }
  6682. else
  6683. {
  6684. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6685. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6686. }
  6687. }
  6688. else
  6689. {
  6690. sscanf(host,"%[^/]%s",host1, path1);
  6691. sprintf(ftppath,"%s", path1);
  6692. int ftppathlen=strlen(ftppath);
  6693. int i=1;
  6694. char filenametemp[50];
  6695. while(i < ftppathlen)
  6696. {
  6697. int len=ftppathlen-i;
  6698. if(ftppath[len]== 47) // '/' ascll code: 47
  6699. {
  6700. DEBUG_INFO("find '/' all right\n");
  6701. break;
  6702. }
  6703. i=i+1;
  6704. }
  6705. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6706. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6707. filenametemp[i+1] = 0;
  6708. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6709. if(port == 0)
  6710. port = 21;
  6711. do{
  6712. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6713. sleep(retryIntervalInt);
  6714. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6715. if(!isSuccess)
  6716. {
  6717. DEBUG_INFO("Diagnostics fail.\n");
  6718. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6719. }
  6720. else
  6721. {
  6722. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6723. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6724. }
  6725. }
  6726. end:
  6727. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6728. pthread_exit(NULL);
  6729. }
  6730. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6731. {
  6732. mtrace();
  6733. int result = FAIL;
  6734. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6735. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6736. {
  6737. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6738. localversion = -1;
  6739. }
  6740. else
  6741. {
  6742. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6743. OCPP_getListVerion();
  6744. }
  6745. //from db.OCPP_getListVerion
  6746. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6747. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6748. sendGetLocalListVersionConfirmation(uuid,"");
  6749. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6750. return result;
  6751. }
  6752. int handleRemoteStartRequest(char *uuid, char *payload)
  6753. {
  6754. mtrace();
  6755. int result = FAIL;
  6756. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6757. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6758. int tempIndex = 0;
  6759. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6760. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6761. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6762. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6763. int chargingSchedulePeriodCount = 0;
  6764. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6765. int c = 0;
  6766. char *loc;
  6767. char comfirmstr[20]={0};
  6768. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6769. if(server_pending == TRUE)
  6770. {
  6771. return 0;
  6772. }
  6773. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6774. strcpy(sstrtemp, stringtrimspace(payload));
  6775. //**********connectorId****************/
  6776. c = 0;
  6777. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6778. loc = strstr(sstrtemp, "connectorId");
  6779. if(loc == NULL)
  6780. {
  6781. connectorIdIsNULL = TRUE;
  6782. }
  6783. else
  6784. {
  6785. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6786. {
  6787. sstr[c] = loc[strlen("connectorId")+2+c];
  6788. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6789. c++;
  6790. }
  6791. sstr[c] = '\0';
  6792. connectorIdInt = atoi(sstr);
  6793. }
  6794. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6795. {
  6796. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6797. goto end;
  6798. }
  6799. //****************idTag*******************/
  6800. c = 0;
  6801. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6802. loc = strstr(sstrtemp, "idTag");
  6803. while (loc[3+strlen("idTag")+c] != '\"')
  6804. {
  6805. sstr[c] = loc[3+strlen("idTag")+c];
  6806. c++;
  6807. }
  6808. sstr[c] = '\0';
  6809. strcpy(idTagstr,sstr);
  6810. //****************chargingProfile*******************/
  6811. c = 0;
  6812. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6813. loc = strstr(sstrtemp, "chargingProfile");
  6814. if(loc == NULL)
  6815. {
  6816. chargingProfileIsNULL = TRUE;
  6817. }
  6818. else
  6819. {
  6820. //****************chargingProfileId*******************/
  6821. c=0;
  6822. loc = strstr(sstrtemp, "chargingProfileId");
  6823. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6824. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6825. {
  6826. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6827. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6828. c++;
  6829. }
  6830. sstr[c] = '\0';
  6831. chargingProfileIdInt = atoi(sstr);
  6832. //****************transactionId*******************/
  6833. loc = strstr(sstrtemp, "transactionId");
  6834. if(loc == NULL)
  6835. {
  6836. transactionIdIsNULL = TRUE;
  6837. }
  6838. else
  6839. {
  6840. c=0;
  6841. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6842. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6843. {
  6844. sstr[c] = loc[strlen("transactionId")+2+c];
  6845. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6846. c++;
  6847. }
  6848. sstr[c] = '\0';
  6849. transactionIdInt = atoi(sstr);
  6850. }
  6851. //****************stackLevel*******************/
  6852. c=0;
  6853. loc = strstr(sstrtemp, "stackLevel");
  6854. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6855. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6856. {
  6857. sstr[c] = loc[strlen("stackLevel")+2+c];
  6858. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6859. c++;
  6860. }
  6861. sstr[c] = '\0';
  6862. stackLevelInt = atoi(sstr);
  6863. //****************chargingProfilePurpose*******************/
  6864. c = 0;
  6865. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6866. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6867. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6868. {
  6869. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6870. c++;
  6871. }
  6872. sstr[c] = '\0';
  6873. strcpy(chargingProfilePurposestr,sstr);
  6874. //****************chargingProfileKind*******************/
  6875. c = 0;
  6876. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6877. loc = strstr(sstrtemp, "chargingProfileKind");
  6878. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6879. {
  6880. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6881. c++;
  6882. }
  6883. sstr[c] = '\0';
  6884. strcpy(chargingProfileKindstr,sstr);
  6885. //****************recurrencyKind*******************/
  6886. loc = strstr(sstrtemp, "recurrencyKind");
  6887. if(loc == NULL)
  6888. {
  6889. recurrencyKindIsNULL = TRUE;
  6890. }
  6891. else
  6892. {
  6893. c = 0;
  6894. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6895. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6896. {
  6897. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6898. c++;
  6899. }
  6900. sstr[c] = '\0';
  6901. strcpy(recurrencyKindstr,sstr);
  6902. }
  6903. //****************validFrom*******************/
  6904. loc = strstr(sstrtemp, "validFrom");
  6905. if(loc == NULL)
  6906. {
  6907. validFromIsNULL = TRUE;
  6908. }
  6909. else
  6910. {
  6911. c = 0;
  6912. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6913. while (loc[3+strlen("validFrom")+c] != '\"')
  6914. {
  6915. sstr[c] = loc[3+strlen("validFrom")+c];
  6916. c++;
  6917. }
  6918. sstr[c] = '\0';
  6919. strcpy(validFromstr,sstr);
  6920. }
  6921. //****************validTo*******************/
  6922. loc = strstr(sstrtemp, "validTo");
  6923. if(loc == NULL)
  6924. {
  6925. validToIsNULL = TRUE;
  6926. }
  6927. else
  6928. {
  6929. c = 0;
  6930. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6931. while (loc[3+strlen("validTo")+c] != '\"')
  6932. {
  6933. sstr[c] = loc[3+strlen("validTo")+c];
  6934. c++;
  6935. }
  6936. sstr[c] = '\0';
  6937. strcpy(validTostr,sstr);
  6938. }
  6939. //****************chargingSchedule*******************/
  6940. loc = strstr(sstrtemp, "chargingSchedule");
  6941. if(loc != NULL)
  6942. {
  6943. //****************duration*******************/
  6944. loc = strstr(sstrtemp, "duration");
  6945. if(loc == NULL)
  6946. {
  6947. durationIsNULL = TRUE;
  6948. }
  6949. else
  6950. {
  6951. c=0;
  6952. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6953. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6954. {
  6955. sstr[c] = loc[strlen("duration")+2+c];
  6956. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6957. c++;
  6958. }
  6959. sstr[c] = '\0';
  6960. durationInt = atoi(sstr);
  6961. }
  6962. //****************startSchedule******************/
  6963. loc = strstr(sstrtemp, "startSchedule");
  6964. if(loc == NULL)
  6965. {
  6966. startScheduleIsNULL = TRUE;
  6967. }
  6968. else
  6969. {
  6970. c = 0;
  6971. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6972. while (loc[3+strlen("startSchedule")+c] != '\"')
  6973. {
  6974. sstr[c] = loc[3+strlen("startSchedule")+c];
  6975. c++;
  6976. }
  6977. sstr[c] = '\0';
  6978. strcpy(startSchedulestr,sstr);
  6979. }
  6980. //****************chargingRateUnit*******************/
  6981. c = 0;
  6982. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6983. loc = strstr(sstrtemp, "chargingRateUnit");
  6984. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6985. {
  6986. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6987. c++;
  6988. }
  6989. sstr[c] = '\0';
  6990. strcpy(chargingRateUnitstr,sstr);
  6991. //****************minChargingRate*******************/
  6992. loc = strstr(sstrtemp, "minChargingRate");
  6993. if(loc == NULL)
  6994. {
  6995. minChargingRateIsNULL = TRUE;
  6996. }
  6997. else
  6998. {
  6999. c=0;
  7000. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7001. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7002. {
  7003. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7005. c++;
  7006. }
  7007. sstr[c] = '\0';
  7008. minChargingRateflaot = atof(sstr);
  7009. }
  7010. //****************chargingSchedulePeriod count*******************/
  7011. int what_len = strlen("startPeriod");
  7012. char *where = sstrtemp;
  7013. while ((where = strstr(where, "startPeriod"))) {
  7014. where += what_len;
  7015. chargingSchedulePeriodCount++;
  7016. }
  7017. where = sstrtemp;
  7018. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7019. {
  7020. //****************startPeriod*******************/
  7021. c=0;
  7022. loc = strstr(where, "startPeriod");
  7023. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7024. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7025. {
  7026. sstr[c] = loc[strlen("startPeriod")+2+c];
  7027. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7028. c++;
  7029. }
  7030. sstr[c] = '\0';
  7031. startPeriodInt[periodNums] = atoi(sstr);
  7032. //****************limit*******************/
  7033. c=0;
  7034. loc = strstr(where, "limit");
  7035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7036. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7037. {
  7038. sstr[c] = loc[strlen("limit")+2+c];
  7039. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7040. c++;
  7041. }
  7042. sstr[c] = '\0';
  7043. limitflaot[periodNums] = atof(sstr);
  7044. //****************numberPhases*******************/
  7045. loc = strstr(where, "numberPhases");
  7046. if(loc == NULL)
  7047. {
  7048. numberPhasesIsNULL = TRUE;
  7049. }
  7050. else
  7051. {
  7052. c=0;
  7053. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7054. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7055. {
  7056. sstr[c] = loc[strlen("numberPhases")+2+c];
  7057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7058. c++;
  7059. }
  7060. sstr[c] = '\0';
  7061. numberPhasesInt[periodNums] = atoi(sstr);
  7062. }
  7063. where = loc;
  7064. } // END FOR chargingSchedulePeriodCount
  7065. }// END IF chargingSchedule
  7066. } // END chargingProfile
  7067. /*
  7068. enum _SYSTEM_STATUS
  7069. {
  7070. S_BOOTING = 0,
  7071. S_IDLE, = 1
  7072. S_AUTHORIZING, =2
  7073. S_REASSIGN_CHECK, =3
  7074. S_REASSIGN, =4
  7075. S_PRECHARGE, =5
  7076. S_PREPARING_FOR_EV, =6
  7077. S_PREPARING_FOR_EVSE, =7
  7078. S_CHARGING, =8
  7079. S_TERMINATING, =9
  7080. S_COMPLETE, =10
  7081. S_ALARM, =11
  7082. S_FAULT =12
  7083. }
  7084. */
  7085. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7086. {
  7087. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7088. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7089. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7090. //check Transaction active
  7091. if(gunType[connectorIdInt -1] == 'J')
  7092. {
  7093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7094. {
  7095. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7096. }
  7097. else
  7098. {
  7099. tempIndex = connectorIdInt -1;
  7100. }
  7101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7102. {
  7103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7104. {
  7105. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7106. {
  7107. //Reserved
  7108. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7109. }
  7110. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7111. {
  7112. //Reserved
  7113. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7115. goto end;
  7116. }
  7117. else
  7118. {
  7119. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7120. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7121. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7122. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7123. {
  7124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7125. goto end;
  7126. }
  7127. }//END FOR ELSE
  7128. }
  7129. }// END FOR CHAdeMO_QUANTITY
  7130. }
  7131. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7132. {
  7133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7134. {
  7135. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7136. }
  7137. else
  7138. {
  7139. tempIndex = connectorIdInt -1;
  7140. }
  7141. for (int index = 0; index < CCS_QUANTITY; index++)
  7142. {
  7143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7144. {
  7145. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7146. {
  7147. //Reserved
  7148. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7149. }
  7150. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7151. {
  7152. //Reserved
  7153. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7154. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7155. goto end;
  7156. }
  7157. else
  7158. {
  7159. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7160. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7161. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7162. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7163. {
  7164. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7165. goto end;
  7166. }
  7167. }// END FOR ELSE
  7168. }
  7169. }// END FOR CCS_QUANTITY
  7170. }
  7171. else if(gunType[connectorIdInt -1] == 'G')
  7172. {
  7173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7174. {
  7175. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7176. }
  7177. else
  7178. {
  7179. tempIndex = connectorIdInt -1;
  7180. }
  7181. for (int index = 0; index < GB_QUANTITY; index++)
  7182. {
  7183. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7184. {
  7185. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7186. {
  7187. //Reserved
  7188. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7189. }
  7190. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7191. {
  7192. //Reserved
  7193. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7195. goto end;
  7196. }
  7197. else
  7198. {
  7199. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7201. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7202. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7203. {
  7204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7205. goto end;
  7206. }
  7207. }// END FOR ELSE
  7208. }
  7209. } // END FOR GB_QUANTITY
  7210. }
  7211. else
  7212. {
  7213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7214. {
  7215. tempIndex = 2;
  7216. }
  7217. else
  7218. {
  7219. tempIndex = connectorIdInt -1;
  7220. }
  7221. for (int index = 0; index < AC_QUANTITY; index++)
  7222. {
  7223. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7224. {
  7225. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7226. {
  7227. //Reserved
  7228. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7229. }
  7230. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7231. {
  7232. //Reserved
  7233. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7235. goto end;
  7236. }
  7237. else
  7238. {
  7239. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7240. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7241. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7242. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7243. {
  7244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7245. goto end;
  7246. }
  7247. }//END FOR ELSE
  7248. }
  7249. }// END FOR AC_QUANTITY
  7250. }
  7251. if(chargingProfileIsNULL == FALSE)
  7252. {
  7253. //ChargingProfile
  7254. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7255. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7256. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7257. if(recurrencyKindIsNULL == FALSE) //OPTION
  7258. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7259. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7260. if(transactionIdIsNULL == FALSE) // OPTION
  7261. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7262. if(validFromIsNULL == FALSE) // OPTION
  7263. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7264. if(validToIsNULL == FALSE) //OPTION
  7265. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7266. //ChargingSchedule
  7267. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7268. if(durationIsNULL == FALSE) //OPTION
  7269. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7270. if(minChargingRateIsNULL == FALSE) //OPTION
  7271. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7272. if(startScheduleIsNULL == FALSE) //OPTION
  7273. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7274. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7275. {
  7276. //ChargingSchedulePeriod
  7277. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7278. if(numberPhasesIsNULL == FALSE)
  7279. {
  7280. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7281. }
  7282. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7283. }
  7284. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7285. {
  7286. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7288. //memset idTag
  7289. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7290. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7291. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7292. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7293. }
  7294. else
  7295. {
  7296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7297. }
  7298. }
  7299. else
  7300. {
  7301. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7302. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7303. //memset idTag
  7304. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7305. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7306. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7307. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7308. }
  7309. }
  7310. else
  7311. {
  7312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7313. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7314. }
  7315. end:
  7316. if(connectorIdIsNULL == FALSE)
  7317. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7318. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7319. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7320. //OCPP send RemoteStartConfirmation by first.
  7321. sendRemoteStartConfirmation(uuid, comfirmstr);
  7322. return result;
  7323. }
  7324. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7325. {
  7326. mtrace();
  7327. int result = FAIL;
  7328. int match = FALSE;
  7329. int GunNO = 0;
  7330. int tempIndex = 0;
  7331. int transactionIdInt=0;
  7332. int transactionIdIsNULL= FALSE;
  7333. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7334. int c = 0;
  7335. char *loc;
  7336. char comfirmstr[20];
  7337. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7338. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7339. if(server_pending == TRUE)
  7340. {
  7341. return 0;
  7342. }
  7343. strcpy(sstrtemp, stringtrimspace(payload));
  7344. c=0;
  7345. loc = strstr(sstrtemp, "transactionId");
  7346. if(loc == NULL)
  7347. {
  7348. transactionIdIsNULL= TRUE;
  7349. }
  7350. else
  7351. {
  7352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7353. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7354. {
  7355. sstr[c] = loc[strlen("transactionId")+2+c];
  7356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7357. c++;
  7358. }
  7359. sstr[c] = '\0';
  7360. transactionIdInt = atoi(sstr);
  7361. }
  7362. if(transactionIdIsNULL == FALSE)
  7363. {
  7364. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7365. {
  7366. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7367. {
  7368. //check Transaction active
  7369. if(gunType[gun_index] == 'J')
  7370. {
  7371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7372. {
  7373. tempIndex = ((gun_index==2) ? 1: 0);
  7374. }
  7375. else
  7376. {
  7377. tempIndex = gun_index;
  7378. }
  7379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7380. {
  7381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7382. {
  7383. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7384. {
  7385. match = TRUE;
  7386. GunNO = gun_index;
  7387. }
  7388. }
  7389. }// END FOR CHAdeMO_QUANTITY
  7390. }
  7391. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7392. {
  7393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7394. {
  7395. tempIndex = ((gun_index==2) ? 1: 0);
  7396. }
  7397. else
  7398. {
  7399. tempIndex = gun_index;
  7400. }
  7401. for (int index = 0; index < CCS_QUANTITY; index++)
  7402. {
  7403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7404. {
  7405. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7406. {
  7407. match = TRUE;
  7408. GunNO = gun_index;
  7409. }
  7410. }
  7411. }// END FOR CCS_QUANTITY
  7412. }
  7413. else if(gunType[gun_index] == 'G')
  7414. {
  7415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7416. {
  7417. tempIndex = ((gun_index==2) ? 1: 0);
  7418. }
  7419. else
  7420. {
  7421. tempIndex = gun_index;
  7422. }
  7423. for (int index = 0; index < GB_QUANTITY; index++)
  7424. {
  7425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7426. {
  7427. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7428. {
  7429. match = TRUE;
  7430. GunNO = gun_index;
  7431. }
  7432. }
  7433. }// END FOR GB_QUANTITY
  7434. }
  7435. else
  7436. {
  7437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7438. {
  7439. tempIndex = 2;
  7440. }
  7441. else
  7442. {
  7443. tempIndex = gun_index;
  7444. }
  7445. for (int index = 0; index < AC_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7448. {
  7449. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7450. {
  7451. match = TRUE;
  7452. GunNO = gun_index;
  7453. }
  7454. }
  7455. }// END FOR CHAdeMO_QUANTITY
  7456. } // END FOR AC ELSE
  7457. }// CHECK IF ResponseTransactionId == transactionIdInt
  7458. }//END FOR
  7459. if( match == TRUE)
  7460. {
  7461. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7462. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7463. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7464. }
  7465. else
  7466. {
  7467. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7468. }
  7469. }
  7470. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7471. return result;
  7472. }
  7473. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7474. {
  7475. mtrace();
  7476. int result = FAIL;
  7477. int connectorIdInt=0, reservationIdInt=0;
  7478. int tempIndex = 0;
  7479. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7480. char comfirmstr[20]={0};
  7481. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7482. int c = 0;
  7483. char *loc;
  7484. //char *ptr;
  7485. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7486. strcpy(sstrtemp, stringtrimspace(payload));
  7487. //***(1)connectorId ****/
  7488. c=0;
  7489. loc = strstr(sstrtemp, "connectorId");
  7490. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7491. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7492. {
  7493. sstr[c] = loc[strlen("connectorId")+2+c];
  7494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7495. c++;
  7496. }
  7497. sstr[c] = '\0';
  7498. connectorIdInt = atoi(sstr);
  7499. //***(2)expiryDate ****/
  7500. loc = strstr(sstrtemp, "expiryDate");
  7501. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7502. c = 0;
  7503. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7504. {
  7505. sstr[c] = loc[3+strlen("expiryDate")+c];
  7506. c++;
  7507. }
  7508. sstr[c] = '\0';
  7509. strcpy(expiryDatestr, sstr);
  7510. //***(3)idTag ****/
  7511. loc = strstr(sstrtemp, "idTag");
  7512. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7513. c = 0;
  7514. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7515. {
  7516. sstr[c] = loc[3+strlen("idTag")+c];
  7517. c++;
  7518. }
  7519. sstr[c] = '\0';
  7520. strcpy(idTagstr, sstr);
  7521. //***(4)parentIdTag ****/
  7522. loc = strstr(sstrtemp, "parentIdTag");
  7523. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7524. c = 0;
  7525. if(loc == NULL)
  7526. {
  7527. strcpy(parentIdTagstr, "");
  7528. }
  7529. else
  7530. {
  7531. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7532. {
  7533. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7534. c++;
  7535. }
  7536. sstr[c] = '\0';
  7537. strcpy(parentIdTagstr, sstr);
  7538. }
  7539. //***(5)reservationId ****/
  7540. c=0;
  7541. loc = strstr(sstrtemp, "reservationId");
  7542. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7543. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7544. {
  7545. sstr[c] = loc[strlen("reservationId")+2+c];
  7546. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7547. c++;
  7548. }
  7549. sstr[c] = '\0';
  7550. reservationIdInt = atoi(sstr);
  7551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7552. /*
  7553. enum SYSTEM_STATUS
  7554. {
  7555. SYS_MODE_BOOTING = 0,
  7556. SYS_MODE_IDLE = 1,
  7557. SYS_MODE_AUTHORIZING = 2,
  7558. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7559. SYS_MODE_REASSIGN = 4,
  7560. SYS_MODE_PREPARING = 5,
  7561. SYS_MODE_PREPARE_FOR_EV = 6,
  7562. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7563. SYS_MODE_CHARGING = 8,
  7564. SYS_MODE_TERMINATING = 9,
  7565. SYS_MODE_COMPLETE = 10,
  7566. SYS_MODE_ALARM = 11,
  7567. SYS_MODE_FAULT = 12,
  7568. SYS_MODE_RESERVATION = 13,
  7569. SYS_MODE_BOOKING = 14,
  7570. SYS_MODE_MAINTAIN = 15,
  7571. SYS_MODE_DEBUG = 16,
  7572. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7573. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7574. SYS_MODE_UPDATE = 19
  7575. };
  7576. */
  7577. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7578. {
  7579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7580. goto end;
  7581. }
  7582. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7583. {
  7584. //check Transaction active
  7585. if(gunType[connectorIdInt -1] == 'J')
  7586. {
  7587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7588. {
  7589. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7590. }
  7591. else
  7592. {
  7593. tempIndex = connectorIdInt -1;
  7594. }
  7595. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7596. {
  7597. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7598. {
  7599. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7600. {
  7601. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7602. {
  7603. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7604. {
  7605. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7607. }
  7608. 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'))
  7609. {
  7610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7611. }
  7612. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7613. {
  7614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7615. }
  7616. else
  7617. {
  7618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7619. }
  7620. }
  7621. 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
  7622. {
  7623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7624. }
  7625. }
  7626. else
  7627. {
  7628. //replace reservation
  7629. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7631. }
  7632. }
  7633. } // END FOR CHAdeMO_QUANTITY
  7634. }
  7635. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7636. {
  7637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7638. {
  7639. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7640. }
  7641. else
  7642. {
  7643. tempIndex = connectorIdInt -1;
  7644. }
  7645. for (int index = 0; index < CCS_QUANTITY; index++)
  7646. {
  7647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7648. {
  7649. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7650. {
  7651. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7652. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7653. {
  7654. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7655. {
  7656. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7658. }
  7659. 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'))
  7660. {
  7661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7662. }
  7663. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7664. {
  7665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7666. }
  7667. else
  7668. {
  7669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7670. }
  7671. }
  7672. 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
  7673. {
  7674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7675. }
  7676. }
  7677. else
  7678. {
  7679. //replace reservation
  7680. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7682. }
  7683. }
  7684. } // END FOR CCS_QUANTITY
  7685. }
  7686. else if(gunType[connectorIdInt -1] == 'G')
  7687. {
  7688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7689. {
  7690. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7691. }
  7692. else
  7693. {
  7694. tempIndex = connectorIdInt -1;
  7695. }
  7696. for (int index = 0; index < GB_QUANTITY; index++)
  7697. {
  7698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7699. {
  7700. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7701. {
  7702. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7703. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7704. {
  7705. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7706. {
  7707. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7709. }
  7710. 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'))
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7713. }
  7714. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7715. {
  7716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7717. }
  7718. else
  7719. {
  7720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7721. }
  7722. }
  7723. 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
  7724. {
  7725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7726. }
  7727. }
  7728. else
  7729. {
  7730. //replace reservation
  7731. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7733. }
  7734. }
  7735. }// END FOR GB_QUANTITY
  7736. }
  7737. else
  7738. {
  7739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7740. {
  7741. tempIndex = 2;
  7742. }
  7743. else
  7744. {
  7745. tempIndex = (connectorIdInt -1);
  7746. }
  7747. for (int index = 0; index < AC_QUANTITY; index++)
  7748. {
  7749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7750. {
  7751. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7752. {
  7753. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7754. {
  7755. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7756. {
  7757. 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))
  7758. {
  7759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7760. }
  7761. else
  7762. {
  7763. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7765. }
  7766. }
  7767. 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'))
  7768. {
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7770. }
  7771. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7772. {
  7773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7774. }
  7775. else
  7776. {
  7777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7778. }
  7779. }
  7780. 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
  7781. {
  7782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7783. }
  7784. }
  7785. else
  7786. {
  7787. //replace reservation
  7788. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7790. }
  7791. }
  7792. } // END FOR AC_QUANTITY
  7793. }
  7794. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7795. }
  7796. else if(connectorIdInt == 0)
  7797. {
  7798. //check Transaction active
  7799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7800. {
  7801. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7802. {
  7803. 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'))
  7804. {
  7805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7806. goto end;
  7807. }
  7808. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7809. {
  7810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7811. goto end;
  7812. }
  7813. 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
  7814. {
  7815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7816. goto end;
  7817. }
  7818. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7819. {
  7820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7821. goto end;
  7822. }
  7823. }
  7824. }// END FOR CHAdeMO_QUANTITY
  7825. for (int index = 0; index < CCS_QUANTITY; index++)
  7826. {
  7827. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7828. {
  7829. 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'))
  7830. {
  7831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7832. goto end;
  7833. }
  7834. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7835. {
  7836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7837. goto end;
  7838. }
  7839. 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
  7840. {
  7841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7842. goto end;
  7843. }
  7844. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7845. {
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7847. goto end;
  7848. }
  7849. }
  7850. } // END FOR CCS_QUANTITY
  7851. for (int index = 0; index < GB_QUANTITY; index++)
  7852. {
  7853. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7854. {
  7855. 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'))
  7856. {
  7857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7858. goto end;
  7859. }
  7860. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7861. {
  7862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7863. goto end;
  7864. }
  7865. 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
  7866. {
  7867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7868. goto end;
  7869. }
  7870. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7871. {
  7872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7873. goto end;
  7874. }
  7875. }
  7876. } // END FOR GB_QUANTITY
  7877. for (int index = 0; index < AC_QUANTITY; index++)
  7878. {
  7879. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7880. {
  7881. 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'))
  7882. {
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7884. goto end;
  7885. }
  7886. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7887. {
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7889. goto end;
  7890. }
  7891. 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
  7892. {
  7893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7894. goto end;
  7895. }
  7896. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7897. {
  7898. 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))
  7899. {
  7900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7901. goto end;
  7902. }
  7903. }
  7904. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7905. {
  7906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7907. goto end;
  7908. }
  7909. }
  7910. }// END FOR AC_QUANTITY
  7911. //The connectorId is 0
  7912. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7914. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7915. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7916. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7917. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7918. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7919. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7920. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7921. result = TRUE;
  7922. return result;
  7923. }
  7924. else
  7925. {
  7926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7927. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7928. }
  7929. if(strcmp(comfirmstr,"Accepted") == 0)
  7930. {
  7931. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7933. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7934. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7935. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7936. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7937. result = TRUE;
  7938. return result;
  7939. }
  7940. end:
  7941. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7942. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7943. return result;
  7944. }
  7945. int handleResetRequest(char *uuid, char *payload)
  7946. {
  7947. mtrace();
  7948. int result = FAIL;
  7949. char sstr[10]={0},sstrtemp[30]={ 0 };
  7950. char typestr[10]={0};
  7951. char comfirmstr[20]={0};
  7952. int c = 0;
  7953. char *loc;
  7954. DEBUG_INFO("handleResetRequest...\n");
  7955. strcpy(sstrtemp, stringtrimspace(payload));
  7956. loc = strstr(sstrtemp, "type");
  7957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7958. c = 0;
  7959. while (loc[3+strlen("type")+c] != '\"')
  7960. {
  7961. sstr[c] = loc[3+strlen("type")+c];
  7962. c++;
  7963. }
  7964. sstr[c] = '\0';
  7965. strcpy(typestr,sstr);
  7966. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7967. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7968. {
  7969. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7970. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7971. result = TRUE;
  7972. return result;
  7973. }
  7974. else
  7975. {
  7976. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7977. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7978. goto errorend;
  7979. }
  7980. errorend:
  7981. sendResetConfirmation(uuid, comfirmstr);
  7982. return result;
  7983. }
  7984. int handleSendLocalListRequest(char *uuid, char *payload)
  7985. {
  7986. mtrace();
  7987. int result = FAIL;
  7988. int listVersionInt;
  7989. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7990. char listsearch[]="listVersion";
  7991. char updateTypesearch[]="updateType";
  7992. char localAuthorizationListsearch[]="localAuthorizationList";
  7993. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7994. char CardList[500][160]={0};
  7995. char updateTypestr[15]={0};
  7996. char idTagstr[20]={0};
  7997. char parentIdTag[20]={0};
  7998. char expiryDate[30]={0};
  7999. char idTagstatus[16]={0};
  8000. int c = 0;
  8001. int i = 0;
  8002. char *delim1 = "}";
  8003. char * pch;
  8004. char *loc;
  8005. //char *ptr;
  8006. char comfirmstr[20];
  8007. //int n_localAuthorizations = 0;
  8008. int checkState_Faulted = FALSE;
  8009. DEBUG_INFO("handleSendLocalListRequest...\n");
  8010. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8011. {
  8012. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8013. goto end;
  8014. }
  8015. //check Charge Point state
  8016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8017. {
  8018. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8019. {
  8020. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8021. }
  8022. }
  8023. for (int index = 0; index < CCS_QUANTITY; index++)
  8024. {
  8025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8026. {
  8027. checkState_Faulted = TRUE; //OCPP Status
  8028. }
  8029. }
  8030. for (int index = 0; index < GB_QUANTITY; index++)
  8031. {
  8032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8033. {
  8034. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8035. }
  8036. }
  8037. //check Charge Point state
  8038. for (int index = 0; index < AC_QUANTITY; index++)
  8039. {
  8040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8041. {
  8042. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8043. }
  8044. }
  8045. if(checkState_Faulted == TRUE)
  8046. {
  8047. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8048. goto end;
  8049. }
  8050. //Filter payload space
  8051. strcpy(sstrtemp, stringtrimspace(payload));
  8052. //listVersion
  8053. c = 0;
  8054. loc = strstr(sstrtemp, listsearch);
  8055. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8056. {
  8057. sstr[c] = loc[strlen("listVersion")+2+c];
  8058. c++;
  8059. }
  8060. sstr[c] = '\0';
  8061. listVersionInt = atoi(sstr);
  8062. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8063. //updateType
  8064. loc = strstr(sstrtemp, updateTypesearch);
  8065. c = 0;
  8066. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8067. {
  8068. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8069. c++;
  8070. }
  8071. sstr[c] = '\0';
  8072. strcpy(updateTypestr, sstr);
  8073. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8074. //localAuthorizationList
  8075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8076. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8077. if(loc != NULL) // localAuthorizationList is not NULL
  8078. {
  8079. //Check UpdateType
  8080. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8081. {
  8082. //Local list full update
  8083. printf("Local list full update.\n");
  8084. OCPP_getListVerion();
  8085. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8086. {
  8087. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8088. goto end;
  8089. }
  8090. OCPP_cleanLocalList();
  8091. }
  8092. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8093. {
  8094. //Local list different update
  8095. printf("Local list different update.\n");
  8096. OCPP_getListVerion();
  8097. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8098. {
  8099. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8100. goto end;
  8101. }
  8102. }
  8103. else
  8104. {
  8105. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8106. goto end;
  8107. }
  8108. c = 0;
  8109. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8110. {
  8111. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8112. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8113. c++;
  8114. }
  8115. sstr[c] = '\0';
  8116. //DEBUG_INFO("sstr=%s\n", sstr);
  8117. //parsing strings to words
  8118. i = 0;
  8119. pch = strtok(sstr,delim1);
  8120. while (pch != NULL)
  8121. {
  8122. strcpy(CardList[i], pch);
  8123. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8124. pch = strtok (NULL, delim1);
  8125. i = i + 1;
  8126. }
  8127. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8128. //local Authorizations List Numbers
  8129. //n_localAuthorizations = i;
  8130. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8131. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8132. c= 0;
  8133. while(c < i) // i is CardList Number
  8134. {
  8135. //Search "IdToken"
  8136. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8137. loc = strstr(CardList[c], "idTag");
  8138. int j = 0;
  8139. while (loc[3+strlen("idTag")+j] != '\"')
  8140. {
  8141. sstr[j] = loc[3+strlen("idTag")+j];
  8142. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8143. j++;
  8144. }
  8145. sstr[j] = '\0';
  8146. strcpy(idTagstr, sstr);
  8147. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8148. //Search "expiryDate"
  8149. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8150. loc = strstr(CardList[c], "expiryDate");
  8151. j = 0;
  8152. if(loc != NULL)
  8153. {
  8154. while (loc[3+strlen("expiryDate")+j] != '\"')
  8155. {
  8156. sstr[j] = loc[3+strlen("expiryDate")+j];
  8157. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8158. j++;
  8159. }
  8160. sstr[j] = '\0';
  8161. strcpy(expiryDate, sstr);
  8162. }
  8163. else
  8164. {
  8165. strcpy(expiryDate, "");
  8166. }
  8167. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8168. //Search "parentIdTag"
  8169. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8170. loc = strstr(CardList[c], "parentIdTag");
  8171. j = 0;
  8172. if(loc != NULL)
  8173. {
  8174. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8175. {
  8176. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8177. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8178. j++;
  8179. }
  8180. sstr[j] = '\0';
  8181. strcpy(parentIdTag, sstr);
  8182. }
  8183. else
  8184. {
  8185. strcpy(parentIdTag, "");
  8186. }
  8187. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8188. //Search "status"
  8189. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8190. loc = strstr(CardList[c], "status");
  8191. j = 0;
  8192. while (loc[3+strlen("status")+j] != '\"')
  8193. {
  8194. sstr[j] = loc[3+strlen("status")+j];
  8195. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8196. j++;
  8197. }
  8198. sstr[j] = '\0';
  8199. strcpy(idTagstatus, sstr);
  8200. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8201. OCPP_getIdTag(idTagstr);
  8202. //OCPP_getIdTag("test"); For Test
  8203. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8204. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8205. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8206. {
  8207. //Local list full update
  8208. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8209. // update list
  8210. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8211. //DEBUG_INFO("Local list full update. 1\n");
  8212. //OCPP_get_TableAuthlocalAllData();
  8213. //DEBUG_INFO("Local list full update. 2\n");
  8214. }
  8215. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8216. {
  8217. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8218. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8219. }
  8220. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8221. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8222. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8223. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8224. c++;
  8225. }
  8226. }
  8227. else
  8228. {
  8229. //Check UpdateType
  8230. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8231. {
  8232. //Local list full update
  8233. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8234. OCPP_cleanLocalList();
  8235. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8236. goto end;
  8237. }
  8238. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8239. {
  8240. //Local list different update
  8241. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8242. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8243. goto end;
  8244. }
  8245. }
  8246. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8247. end:
  8248. sendSendLocalListConfirmation(uuid, comfirmstr);
  8249. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8250. return result;
  8251. }
  8252. #define MAX 200
  8253. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8254. {
  8255. mtrace();
  8256. int result = FAIL;
  8257. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8258. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8259. char chargingProfilePurposeStr[30]={0};
  8260. char chargingProfileKindStr[16]={0};
  8261. char recurrencyKindStr[10]={0};
  8262. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8263. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8264. int chargingSchedulePeriodCount = 0;
  8265. //int updateflag = FALSE;
  8266. char comfirmstr[20]={0};
  8267. int meet= FALSE;
  8268. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8269. int c = 0;
  8270. char *loc;
  8271. FILE *fptr1;//, *fptr2;
  8272. //int lno=0;//, linectr = 0;
  8273. //int modifyflag = FALSE;
  8274. char filename[MAX]={0};
  8275. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8276. //int resultRename=0;
  8277. char rmFileCmd[50]={0};
  8278. char tempchargingProfilePurposeStr[30]={0};
  8279. char word[1600]={0};
  8280. int n_chargingProfile = 0;
  8281. //[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}}}]
  8282. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8283. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8284. //Filter string space
  8285. strcpy(sstrtemp, stringtrimspace(payload));
  8286. //*********************connectorId***************************/
  8287. loc = strstr(sstrtemp, "connectorId");
  8288. c = 0;
  8289. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8290. while (loc[strlen("connectorId")+2+c] != ',')
  8291. {
  8292. sstr[c] = loc[strlen("connectorId")+2+c];
  8293. c++;
  8294. }
  8295. sstr[c] = '\0';
  8296. connectorIdInt = atoi(sstr);
  8297. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8298. {
  8299. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8300. }
  8301. else
  8302. {
  8303. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8304. }
  8305. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8306. //*********************chargingProfileId***************************/
  8307. loc = strstr(sstrtemp, "chargingProfileId");
  8308. c = 0;
  8309. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8310. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8311. {
  8312. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8313. c++;
  8314. }
  8315. sstr[c] = '\0';
  8316. chargingProfileIdInt = atoi(sstr);
  8317. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8318. {
  8319. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8320. }
  8321. else
  8322. {
  8323. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8324. }
  8325. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8326. //*********************transactionId***************************/
  8327. loc = strstr(sstrtemp, "transactionId");
  8328. if(loc != NULL)
  8329. {
  8330. c = 0;
  8331. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8332. while (loc[strlen("transactionId")+2+c] != ',')
  8333. {
  8334. sstr[c] = loc[strlen("transactionId")+2+c];
  8335. c++;
  8336. }
  8337. sstr[c] = '\0';
  8338. transactionIdInt = atoi(sstr);
  8339. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8340. {
  8341. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8342. }
  8343. else
  8344. {
  8345. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8346. }
  8347. }
  8348. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8349. //*********************stackLevel***************************/
  8350. loc = strstr(sstrtemp, "stackLevel");
  8351. c = 0;
  8352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8353. while (loc[strlen("stackLevel")+2+c] != ',')
  8354. {
  8355. sstr[c] = loc[strlen("stackLevel")+2+c];
  8356. c++;
  8357. }
  8358. sstr[c] = '\0';
  8359. stackLevelInt = atoi(sstr);
  8360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8361. {
  8362. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8363. }
  8364. else
  8365. {
  8366. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8367. }
  8368. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8369. //*********************chargingProfilePurpose***************************/
  8370. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8371. c = 0;
  8372. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8373. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8374. {
  8375. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8376. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8377. c++;
  8378. }
  8379. sstr[c] = '\0';
  8380. strcpy(chargingProfilePurposeStr,sstr);
  8381. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8382. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8383. {
  8384. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8385. }
  8386. else
  8387. {
  8388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8389. }
  8390. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8391. //*********************chargingProfileKind***************************/
  8392. loc = strstr(sstrtemp, "chargingProfileKind");
  8393. c = 0;
  8394. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8395. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8396. {
  8397. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8398. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8399. c++;
  8400. }
  8401. sstr[c] = '\0';
  8402. strcpy(chargingProfileKindStr,sstr);
  8403. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8404. {
  8405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8406. }
  8407. else
  8408. {
  8409. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8410. }
  8411. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8412. //*********************recurrencyKind***************************/
  8413. loc = strstr(sstrtemp, "recurrencyKind");
  8414. if(loc != NULL)
  8415. {
  8416. c = 0;
  8417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8418. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8419. {
  8420. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8422. c++;
  8423. }
  8424. sstr[c] = '\0';
  8425. strcpy(recurrencyKindStr,sstr);
  8426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8427. {
  8428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8429. }
  8430. else
  8431. {
  8432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8433. }
  8434. }
  8435. else
  8436. {
  8437. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8438. {
  8439. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8440. }
  8441. else
  8442. {
  8443. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8444. }
  8445. }
  8446. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8447. //*********************validFrom***************************/
  8448. loc = strstr(sstrtemp, "validFrom");
  8449. if(loc != NULL)
  8450. {
  8451. c = 0;
  8452. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8453. while (loc[3+strlen("validFrom")+c] != '\"')
  8454. {
  8455. sstr[c] = loc[3+strlen("validFrom")+c];
  8456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8457. c++;
  8458. }
  8459. sstr[c] = '\0';
  8460. strcpy(validFromStr,sstr);
  8461. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8462. {
  8463. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8464. }
  8465. else
  8466. {
  8467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8468. }
  8469. }
  8470. else
  8471. {
  8472. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8473. {
  8474. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8475. }
  8476. else
  8477. {
  8478. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8479. }
  8480. }
  8481. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8482. //*********************validTo***************************/
  8483. loc = strstr(sstrtemp, "validTo");
  8484. if(loc != NULL)
  8485. {
  8486. c = 0;
  8487. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8488. while (loc[3+strlen("validTo")+c] != '\"')
  8489. {
  8490. sstr[c] = loc[3+strlen("validTo")+c];
  8491. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8492. c++;
  8493. }
  8494. sstr[c] = '\0';
  8495. strcpy(validToStr,sstr);
  8496. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8497. {
  8498. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8499. }
  8500. else
  8501. {
  8502. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8503. }
  8504. }
  8505. else
  8506. {
  8507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8508. {
  8509. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8510. }
  8511. else
  8512. {
  8513. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8514. }
  8515. }
  8516. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8517. //*********************duration***************************/
  8518. loc = strstr(sstrtemp, "duration");
  8519. if(loc != NULL)
  8520. {
  8521. c = 0;
  8522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8523. while (loc[strlen("duration")+2+c] != ',')
  8524. {
  8525. sstr[c] = loc[strlen("duration")+2+c];
  8526. c++;
  8527. }
  8528. sstr[c] = '\0';
  8529. durationInt = atoi(sstr);
  8530. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8531. {
  8532. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8533. }
  8534. else
  8535. {
  8536. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8537. }
  8538. }
  8539. else
  8540. {
  8541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8542. {
  8543. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8544. }
  8545. else
  8546. {
  8547. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8548. }
  8549. }
  8550. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8551. //*********************startSchedule***************************/
  8552. loc = strstr(sstrtemp, "startSchedule");
  8553. if(loc != NULL)
  8554. {
  8555. c = 0;
  8556. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8557. while (loc[3+strlen("startSchedule")+c] != '\"')
  8558. {
  8559. sstr[c] = loc[3+strlen("startSchedule")+c];
  8560. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8561. c++;
  8562. }
  8563. sstr[c] = '\0';
  8564. strcpy(startScheduleStr,sstr);
  8565. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8566. {
  8567. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8568. }
  8569. else
  8570. {
  8571. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8572. }
  8573. }
  8574. else
  8575. {
  8576. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8577. {
  8578. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8579. }
  8580. else
  8581. {
  8582. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8583. }
  8584. }
  8585. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8586. //*********************chargingRateUnit***************************/
  8587. loc = strstr(sstrtemp, "chargingRateUnit");
  8588. if(loc != NULL)
  8589. {
  8590. c = 0;
  8591. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8592. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8593. {
  8594. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8596. c++;
  8597. }
  8598. sstr[c] = '\0';
  8599. strcpy(chargingRateUnitStr,sstr);
  8600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8601. {
  8602. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8603. }
  8604. else
  8605. {
  8606. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8607. }
  8608. }
  8609. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8610. //****************chargingSchedulePeriod count start*******************/
  8611. int what_len = strlen("startPeriod");
  8612. char tempChargingProfile[1600]={0};
  8613. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8614. char *where = tempChargingProfile;
  8615. if (what_len)
  8616. {
  8617. while ((where = strstr(where, "startPeriod"))) {
  8618. where += what_len;
  8619. chargingSchedulePeriodCount++;
  8620. }
  8621. }
  8622. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8623. {
  8624. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8625. goto end;
  8626. }
  8627. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8628. //where = payload;
  8629. int templength = 0;
  8630. //int searchstart = 0;
  8631. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8632. {
  8633. //****************startPeriod*******************/
  8634. c=0;
  8635. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8636. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8637. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8638. {
  8639. sstr[c] = loc[strlen("startPeriod")+2+c];
  8640. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8641. c++;
  8642. }
  8643. sstr[c] = '\0';
  8644. startPeriodInt[periodNums] = atoi(sstr);
  8645. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8646. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8647. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8648. {
  8649. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8650. }
  8651. else
  8652. {
  8653. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8654. }
  8655. templength = strlen("startPeriod")+2+c;
  8656. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8657. //****************limit*******************/
  8658. c=0;
  8659. loc = strstr(tempChargingProfile + templength, "limit");
  8660. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8661. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8662. {
  8663. sstr[c] = loc[strlen("limit")+2+c];
  8664. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8665. c++;
  8666. }
  8667. sstr[c] = '\0';
  8668. limitflaot[periodNums] = atof(sstr);
  8669. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8670. {
  8671. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8672. }
  8673. else
  8674. {
  8675. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8676. }
  8677. templength = templength + strlen("limit")+2+c;
  8678. //****************numberPhases*******************/
  8679. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8680. if(loc != NULL)
  8681. {
  8682. c=0;
  8683. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8684. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8685. {
  8686. sstr[c] = loc[strlen("numberPhases")+2+c];
  8687. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8688. c++;
  8689. }
  8690. sstr[c] = '\0';
  8691. numberPhasesInt[periodNums] = atoi(sstr);
  8692. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8693. {
  8694. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8695. }
  8696. else
  8697. {
  8698. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8699. }
  8700. templength = templength + strlen("numberPhases")+2+c;
  8701. }
  8702. //where = loc;
  8703. }
  8704. //****************chargingSchedulePeriod count end*******************/
  8705. //*********************minChargingRate***************************/
  8706. loc = strstr(sstrtemp, "minChargingRate");
  8707. if(loc != NULL)
  8708. {
  8709. c = 0;
  8710. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8711. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8712. {
  8713. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8714. c++;
  8715. }
  8716. sstr[c] = '\0';
  8717. minChargingRateFloat = atof(sstr);
  8718. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8719. {
  8720. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8721. }
  8722. else
  8723. {
  8724. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8725. }
  8726. }
  8727. else
  8728. {
  8729. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8730. {
  8731. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8732. }
  8733. else
  8734. {
  8735. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8736. }
  8737. }
  8738. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8739. {
  8740. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8741. if(connectorIdInt != 0)
  8742. {
  8743. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8744. goto end;
  8745. }
  8746. strcpy(filename, ChargePointMaxProfile_JSON );
  8747. fptr1 = fopen(filename, "r");
  8748. if (!fptr1)
  8749. {
  8750. //file not exist
  8751. DEBUG_INFO("Unable to open the input file!!\n");
  8752. fptr1 = fopen(filename, "w+");
  8753. }
  8754. else
  8755. {
  8756. //Check Charging Profile Count
  8757. while(fscanf(fptr1, "%s", word) != EOF)
  8758. {
  8759. //DEBUG_INFO("word=%s\n",word);
  8760. if(strstr(word, "chargingProfileId")!= NULL)
  8761. {
  8762. //DEBUG_INFO("test chargingProfileId \n");
  8763. n_chargingProfile = n_chargingProfile + 1;
  8764. //DEBUG_INFO("chargingProfileId Found\n");
  8765. }
  8766. }
  8767. }
  8768. fclose(fptr1);
  8769. }
  8770. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8771. {
  8772. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8773. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8774. {
  8775. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8776. goto end;
  8777. }
  8778. memset(filename, 0, ARRAY_SIZE(filename));
  8779. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8780. fptr1 = fopen(filename, "r");
  8781. if (!fptr1)
  8782. {
  8783. //file not exist
  8784. //DEBUG_INFO("Unable to open the input file!!\n");
  8785. fptr1 = fopen(filename, "w+");
  8786. }
  8787. else
  8788. {
  8789. //Check Charging Profile Count
  8790. while(fscanf(fptr1, "%s", word) != EOF)
  8791. {
  8792. //DEBUG_INFO("word=%s\n",word);
  8793. if(strstr(word, "chargingProfileId")!= NULL)
  8794. {
  8795. //DEBUG_INFO("test chargingProfileId \n");
  8796. n_chargingProfile = n_chargingProfile + 1;
  8797. //DEBUG_INFO("chargingProfileId Found\n");
  8798. }
  8799. }
  8800. }
  8801. fclose(fptr1);
  8802. }
  8803. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8804. {
  8805. //printf("set chargingProfile 1-4\n");
  8806. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8807. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8808. if(connectorIdInt == 0)
  8809. {
  8810. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8811. goto end;
  8812. }
  8813. int tempIndex = 0;
  8814. //check Transaction active
  8815. if(gunType[connectorIdInt -1] == 'J')
  8816. {
  8817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8818. {
  8819. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8820. }
  8821. else
  8822. {
  8823. tempIndex = connectorIdInt -1;
  8824. }
  8825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8826. {
  8827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8828. {
  8829. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8830. {
  8831. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8832. {
  8833. meet = TRUE;
  8834. break;
  8835. }
  8836. }
  8837. }
  8838. }
  8839. }
  8840. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8841. {
  8842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8843. {
  8844. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8845. }
  8846. else
  8847. {
  8848. tempIndex = connectorIdInt -1;
  8849. }
  8850. for (int index = 0; index < CCS_QUANTITY; index++)
  8851. {
  8852. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8853. {
  8854. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8855. {
  8856. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8857. {
  8858. meet = TRUE;
  8859. break;
  8860. }
  8861. }
  8862. }
  8863. }
  8864. }
  8865. else if(gunType[connectorIdInt -1] == 'G')
  8866. {
  8867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8868. {
  8869. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8870. }
  8871. else
  8872. {
  8873. tempIndex = connectorIdInt -1;
  8874. }
  8875. for (int index = 0; index < GB_QUANTITY; index++)
  8876. {
  8877. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8878. {
  8879. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8880. {
  8881. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8882. {
  8883. meet = TRUE;
  8884. break;
  8885. }
  8886. }
  8887. }
  8888. }
  8889. }
  8890. else
  8891. {
  8892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8893. {
  8894. tempIndex = 2;
  8895. }
  8896. else
  8897. {
  8898. tempIndex = (connectorIdInt -1);
  8899. }
  8900. for (int index = 0; index < AC_QUANTITY; index++)
  8901. {
  8902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8903. {
  8904. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8905. {
  8906. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8907. {
  8908. meet = TRUE;
  8909. break;
  8910. }
  8911. }
  8912. }
  8913. }
  8914. }
  8915. //check Transaction active
  8916. if(meet == FALSE)
  8917. {
  8918. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8919. goto end;
  8920. }
  8921. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8922. {
  8923. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8924. goto end;
  8925. }
  8926. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8927. fptr1 = fopen(filename, "r");
  8928. if (!fptr1)
  8929. {
  8930. //file not exist
  8931. DEBUG_INFO("Unable to open the input file!!\n");
  8932. fptr1 = fopen(filename, "w+");
  8933. }
  8934. else
  8935. {
  8936. //Check Charging Profile Count
  8937. while(fscanf(fptr1, "%s", word) != EOF)
  8938. {
  8939. //DEBUG_INFO("word=%s\n",word);
  8940. if(strstr(word, "chargingProfileId")!= NULL)
  8941. {
  8942. //DEBUG_INFO("test chargingProfileId \n");
  8943. n_chargingProfile = n_chargingProfile + 1;
  8944. //DEBUG_INFO("chargingProfileId Found\n");
  8945. }
  8946. }
  8947. }
  8948. fclose(fptr1);
  8949. }
  8950. // Check ChargeProfileMaxStackLevel
  8951. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8952. {
  8953. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8954. goto end;
  8955. }
  8956. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8957. {
  8958. int i = 0;
  8959. char fnametemp[200]={0};
  8960. n_chargingProfile = 0;
  8961. //Check ChargePointMaxProfile.json exit
  8962. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8963. {
  8964. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8965. //Check Charging Profile Count
  8966. while(fscanf(fptr1, "%s", word) != EOF)
  8967. {
  8968. //DEBUG_INFO("word=%s\n",word);
  8969. if(strstr(word, "chargingProfileId")!= NULL)
  8970. {
  8971. //DEBUG_INFO("test chargingProfileId \n");
  8972. n_chargingProfile = n_chargingProfile + 1;
  8973. i = i + 1;
  8974. //DEBUG_INFO("chargingProfileId Found\n");
  8975. }
  8976. memset(word, 0, ARRAY_SIZE(word));
  8977. }
  8978. fclose(fptr1);
  8979. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8980. }
  8981. //Check TxDefaultProfile_0.json exit
  8982. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8983. {
  8984. i = 0;
  8985. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8986. //Check Charging Profile Count
  8987. while(fscanf(fptr1, "%s", word) != EOF)
  8988. {
  8989. //DEBUG_INFO("word=%s\n",word);
  8990. if(strstr(word, "chargingProfileId")!= NULL)
  8991. {
  8992. //DEBUG_INFO("test chargingProfileId \n");
  8993. n_chargingProfile = n_chargingProfile + 1;
  8994. i = i + 1;
  8995. //DEBUG_INFO("chargingProfileId Found\n");
  8996. }
  8997. memset(word, 0, ARRAY_SIZE(word));
  8998. }
  8999. fclose(fptr1);
  9000. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9001. }
  9002. //Check TxDefaultProfile_%d.json
  9003. for(int j=1; j <= gunTotalNumber; j++)
  9004. {
  9005. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9006. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9007. if((access(fnametemp,F_OK))!=-1)
  9008. {
  9009. i = 0;
  9010. fptr1 = fopen(fnametemp, "r");
  9011. //Check Charging Profile Count
  9012. while(fscanf(fptr1, "%s", word) != EOF)
  9013. {
  9014. //DEBUG_INFO("word=%s\n",word);
  9015. if(strstr(word, "chargingProfileId")!= NULL)
  9016. {
  9017. //DEBUG_INFO("test chargingProfileId \n");
  9018. n_chargingProfile = n_chargingProfile + 1;
  9019. i = i + 1;
  9020. //DEBUG_INFO("chargingProfileId Found\n");
  9021. }
  9022. memset(word, 0, ARRAY_SIZE(word));
  9023. }
  9024. fclose(fptr1);
  9025. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9026. }
  9027. }
  9028. //Check TxProfile_%d.json
  9029. for(int j=1; j <= gunTotalNumber; j++)
  9030. {
  9031. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9032. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9033. if((access(fnametemp,F_OK))!=-1)
  9034. {
  9035. i = 0;
  9036. fptr1 = fopen(fnametemp, "r");
  9037. //Check Charging Profile Count
  9038. while(fscanf(fptr1, "%s", word) != EOF)
  9039. {
  9040. //DEBUG_INFO("word=%s\n",word);
  9041. if(strstr(word, "chargingProfileId")!= NULL)
  9042. {
  9043. //DEBUG_INFO("test chargingProfileId \n");
  9044. n_chargingProfile = n_chargingProfile + 1;
  9045. i = i + 1;
  9046. //DEBUG_INFO("chargingProfileId Found\n");
  9047. }
  9048. memset(word, 0, ARRAY_SIZE(word));
  9049. }
  9050. fclose(fptr1);
  9051. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9052. }
  9053. }
  9054. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9055. {
  9056. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9057. goto end;
  9058. }
  9059. }
  9060. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9061. //**********************************Write to File********************************************************/
  9062. FILE *infile;
  9063. FILE *outfile;
  9064. // open file for writing
  9065. infile = fopen (filename, "r");
  9066. outfile = fopen (tempfile, "w");
  9067. int d =0;
  9068. d = fgetc(infile);
  9069. //DEBUG_INFO("d:%d\n",d);
  9070. rewind(infile);
  9071. //*璉 瘚 辣蝏     1嚗   0 */
  9072. if(d == EOF)
  9073. {
  9074. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9075. fprintf(outfile,"%s\n",payload);
  9076. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9077. fclose(infile);
  9078. fclose(outfile);
  9079. sprintf(rmFileCmd,"rm -f %s",filename);
  9080. system(rmFileCmd);
  9081. rename(tempfile, filename);
  9082. sleep(1);
  9083. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9084. //system(rmFileCmd);
  9085. }
  9086. else
  9087. {
  9088. char buf[1000]={0};
  9089. int ChargingProfileAdded = FALSE;
  9090. while (fgets(buf, sizeof(buf), infile) != NULL)
  9091. {
  9092. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9093. //*************************tempconnectorIdInt*********************************/
  9094. loc = strstr(buf, "connectorId");
  9095. c = 0;
  9096. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9097. while (loc[strlen("connectorId")+2+c] != ',')
  9098. {
  9099. sstr[c] = loc[strlen("connectorId")+2+c];
  9100. c++;
  9101. }
  9102. sstr[c] = '\0';
  9103. tempconnectorIdInt = atoi(sstr);
  9104. //*************************tempchargingProfileIdInt*********************************/
  9105. loc = strstr(buf, "chargingProfileId");
  9106. c = 0;
  9107. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9108. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9109. {
  9110. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9111. c++;
  9112. }
  9113. sstr[c] = '\0';
  9114. tempchargingProfileIdInt = atoi(sstr);
  9115. //*************************tempstackLevelInt*********************************/
  9116. loc = strstr(buf, "stackLevel");
  9117. c = 0;
  9118. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9119. while (loc[strlen("stackLevel")+2+c] != ',')
  9120. {
  9121. sstr[c] = loc[strlen("stackLevel")+2+c];
  9122. c++;
  9123. }
  9124. sstr[c] = '\0';
  9125. tempstackLevelInt = atoi(sstr);
  9126. //*************************tempchargingProfilePurposeStr*********************************/
  9127. loc = strstr(payload, "chargingProfilePurpose");
  9128. c = 0;
  9129. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9130. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9131. {
  9132. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9133. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9134. c++;
  9135. }
  9136. sstr[c] = '\0';
  9137. strcpy(tempchargingProfilePurposeStr,sstr);
  9138. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9139. {
  9140. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9141. {
  9142. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9143. if(ChargingProfileAdded == FALSE)
  9144. {
  9145. fprintf(outfile,"%s\n",payload);
  9146. ChargingProfileAdded = TRUE;
  9147. }
  9148. }
  9149. else
  9150. {
  9151. if(tempstackLevelInt < stackLevelInt)
  9152. {
  9153. if(ChargingProfileAdded == FALSE)
  9154. {
  9155. fprintf(outfile,"%s\n",payload);
  9156. ChargingProfileAdded = TRUE;
  9157. fprintf(outfile,"%s\n",buf);
  9158. }
  9159. else
  9160. {
  9161. fprintf(outfile,"%s\n",buf);
  9162. }
  9163. }
  9164. else
  9165. {
  9166. if(ChargingProfileAdded == FALSE)
  9167. {
  9168. fprintf(outfile,"%s\n",buf);
  9169. fprintf(outfile,"%s\n",payload);
  9170. ChargingProfileAdded = TRUE;
  9171. }
  9172. else
  9173. {
  9174. fprintf(outfile,"%s\n",buf);
  9175. }
  9176. }
  9177. }
  9178. }
  9179. else
  9180. {
  9181. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9182. {
  9183. if(ChargingProfileAdded == FALSE)
  9184. {
  9185. fprintf(outfile,"%s\n",payload);
  9186. ChargingProfileAdded = TRUE;
  9187. fprintf(outfile,"%s\n",buf);
  9188. }
  9189. else
  9190. {
  9191. fprintf(outfile,"%s\n",buf);
  9192. }
  9193. }
  9194. else if(tempstackLevelInt < stackLevelInt)
  9195. {
  9196. if(ChargingProfileAdded == FALSE)
  9197. {
  9198. fprintf(outfile,"%s\n",payload);
  9199. ChargingProfileAdded = TRUE;
  9200. fprintf(outfile,"%s\n",buf);
  9201. }
  9202. else
  9203. {
  9204. fprintf(outfile,"%s\n",buf);
  9205. }
  9206. }
  9207. else
  9208. {
  9209. if(ChargingProfileAdded == FALSE)
  9210. {
  9211. fprintf(outfile,"%s\n",buf);
  9212. fprintf(outfile,"%s\n",payload);
  9213. ChargingProfileAdded = TRUE;
  9214. }
  9215. else
  9216. {
  9217. fprintf(outfile,"%s\n",buf);
  9218. }
  9219. }
  9220. }
  9221. } // end of while loop
  9222. fclose(infile);
  9223. fclose(outfile);
  9224. sprintf(rmFileCmd,"rm -f %s",filename);
  9225. system(rmFileCmd);
  9226. rename(tempfile, filename);
  9227. sleep(1);
  9228. result = TRUE;
  9229. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9230. }
  9231. end:
  9232. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9233. return result;
  9234. return result;
  9235. }
  9236. int handleTriggerMessageRequest(char *uuid, char *payload)
  9237. {
  9238. mtrace();
  9239. int result = FAIL;
  9240. int connectorIdIsNULL = FALSE;
  9241. int connectorIdInt =0;
  9242. char sstr[40]={0},sstrtemp[100]={ 0 };
  9243. char requestedMessagestr[40]={0};
  9244. char comfirmstr[20]={0};
  9245. int c = 0;
  9246. char *loc;
  9247. DEBUG_INFO("handleTriggerMessageRequest\n");
  9248. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9249. strcpy(sstrtemp, stringtrimspace(payload));
  9250. c = 0;
  9251. loc = strstr(sstrtemp, "requestedMessage");
  9252. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9253. {
  9254. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9255. c++;
  9256. }
  9257. sstr[c] = '\0';
  9258. strcpy(requestedMessagestr, sstr);
  9259. c = 0;
  9260. loc = strstr(sstrtemp, "connectorId");
  9261. if(loc == NULL)
  9262. {
  9263. connectorIdIsNULL = TRUE;
  9264. }
  9265. else
  9266. {
  9267. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9268. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9269. {
  9270. sstr[c] = loc[strlen("connectorId")+2+c];
  9271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9272. c++;
  9273. }
  9274. sstr[c] = '\0';
  9275. connectorIdInt = atoi(sstr);
  9276. }
  9277. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9278. {
  9279. //connectorIdInt = json_object_get_int(connectorId);
  9280. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9281. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9282. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9283. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9284. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9285. }
  9286. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9287. {
  9288. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9289. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9290. return TRUE;
  9291. }
  9292. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9293. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9294. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9295. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9296. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9297. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9298. {
  9299. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9300. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9301. return TRUE;
  9302. }
  9303. else
  9304. {
  9305. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9306. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9307. }
  9308. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9309. {
  9310. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9311. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9312. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9313. {
  9314. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9315. }
  9316. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9317. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9318. }
  9319. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9320. {
  9321. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9322. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9323. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9324. }
  9325. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9326. {
  9327. sendBootNotificationRequest();
  9328. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9329. }
  9330. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9331. {
  9332. sendHeartbeatRequest(connectorIdInt);
  9333. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9334. }
  9335. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9336. {
  9337. if(connectorIdIsNULL == FALSE)
  9338. {
  9339. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9340. {
  9341. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9342. sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9343. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9344. }
  9345. }
  9346. else
  9347. {
  9348. for(int idx=0;idx< gunTotalNumber;idx++)
  9349. {
  9350. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9351. sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9352. }
  9353. }
  9354. }
  9355. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9356. {
  9357. if(connectorIdIsNULL == FALSE)
  9358. {
  9359. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9360. {
  9361. sendStatusNotificationRequest(connectorIdInt -1);
  9362. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9363. }
  9364. }
  9365. else
  9366. {
  9367. for(int idx=0;idx< gunTotalNumber;idx++)
  9368. sendStatusNotificationRequest(idx);
  9369. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9370. }
  9371. }
  9372. return result;
  9373. }
  9374. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9375. {
  9376. mtrace();
  9377. int result = FAIL;
  9378. char sstr[6]={0},sstrtemp[50]={ 0 };
  9379. int connectorIdInt =0;
  9380. char comfirmstr[20]={0};
  9381. int c = 0;
  9382. int tempIndex = 0;
  9383. char *loc;
  9384. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9385. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9386. strcpy(sstrtemp, stringtrimspace(payload));
  9387. c = 0;
  9388. loc = strstr(sstrtemp, "connectorId");
  9389. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9390. while (loc[strlen("connectorId")+2+c] != '}')
  9391. {
  9392. sstr[c] = loc[strlen("connectorId")+2+c];
  9393. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9394. c++;
  9395. }
  9396. sstr[c] = '\0';
  9397. connectorIdInt = atoi(sstr);
  9398. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9399. if(gunTotalNumber == 0)
  9400. {
  9401. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9402. goto end;
  9403. }
  9404. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9405. {
  9406. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9407. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9408. goto end;
  9409. }
  9410. else
  9411. {
  9412. //check Transaction active
  9413. if(gunType[connectorIdInt-1] == 'J')
  9414. {
  9415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9416. {
  9417. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9418. }
  9419. else
  9420. {
  9421. tempIndex = connectorIdInt -1;
  9422. }
  9423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9424. {
  9425. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9426. {
  9427. //stop Transaction
  9428. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9429. }
  9430. }
  9431. }
  9432. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9433. {
  9434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9435. {
  9436. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9437. }
  9438. else
  9439. {
  9440. tempIndex = connectorIdInt -1;
  9441. }
  9442. for (int index = 0; index < CCS_QUANTITY; index++)
  9443. {
  9444. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9445. {
  9446. //stop Transaction
  9447. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9448. }
  9449. }
  9450. }
  9451. else if(gunType[connectorIdInt-1] == 'G')
  9452. {
  9453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9454. {
  9455. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9456. }
  9457. else
  9458. {
  9459. tempIndex = connectorIdInt -1;
  9460. }
  9461. for (int index = 0; index < GB_QUANTITY; index++)
  9462. {
  9463. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9464. {
  9465. //stop Transaction
  9466. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9467. }
  9468. }
  9469. }
  9470. else
  9471. {
  9472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9473. {
  9474. tempIndex = 2;
  9475. }
  9476. else
  9477. {
  9478. tempIndex = connectorIdInt-1;
  9479. }
  9480. for (int index = 0; index < AC_QUANTITY; index++)
  9481. {
  9482. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9483. {
  9484. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9485. }
  9486. }
  9487. }
  9488. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9489. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9490. result = TRUE;
  9491. return result;
  9492. }
  9493. end:
  9494. //json_object_put(obj); --- remove temporally
  9495. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9496. return result;
  9497. }
  9498. static char UpdateFirmwarepayloadData[300]={0};
  9499. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9500. {
  9501. mtrace();
  9502. int result = FAIL;
  9503. pthread_t t;
  9504. sendUpdateFirmwareConfirmation(uuid);
  9505. memset(UpdateFirmwarepayloadData, 0, 300);
  9506. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9507. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9508. ////pthread_join(t, NULL); //
  9509. //pthread_detach(t);
  9510. //sendUpdateFirmwareConfirmation(uuid);
  9511. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9512. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9513. return result;
  9514. }
  9515. void *UpdateFirmwareProcess(void *data)
  9516. {
  9517. pthread_detach(pthread_self());
  9518. mtrace();
  9519. int retriesInt =0, retryIntervalInt=0;
  9520. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9521. int port=0;
  9522. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9523. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9524. //char comfirmstr[20];
  9525. int isSuccess = 0;
  9526. char ftpbuf[200];
  9527. char temp[100];
  9528. char * pch;
  9529. int retriesISNULL=FALSE;
  9530. int retryInterval=FALSE;
  9531. int c = 0;
  9532. //int i = 0;
  9533. char *loc;
  9534. char sstr[300]={ 0 };
  9535. char str[300]={ 0 };
  9536. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9537. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9538. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9539. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9540. //***************location **************/
  9541. loc = strstr(str, "location");
  9542. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9543. c = 0;
  9544. while (loc[3+strlen("location")+c] != '\"')
  9545. {
  9546. sstr[c] = loc[3+strlen("location")+c];
  9547. c++;
  9548. }
  9549. sstr[c] = '\0';
  9550. strcpy(locationstr, sstr);
  9551. //***************retries**************/
  9552. c = 0;
  9553. loc = strstr(str, "retries");
  9554. if(loc == NULL)
  9555. {
  9556. retriesISNULL=TRUE;
  9557. }
  9558. else
  9559. {
  9560. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9561. while (loc[strlen("retries")+2+c] != ',')
  9562. {
  9563. sstr[c] = loc[strlen("retries")+2+c];
  9564. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9565. c++;
  9566. }
  9567. sstr[c] = '\0';
  9568. }
  9569. if(retriesISNULL == FALSE)
  9570. {
  9571. retriesInt = atoi(sstr);
  9572. }
  9573. //***************retrieveDate **************/
  9574. loc = strstr(str, "retrieveDate");
  9575. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9576. c = 0;
  9577. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9578. {
  9579. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9580. c++;
  9581. }
  9582. sstr[c] = '\0';
  9583. strcpy(retrieveDatestr, sstr);
  9584. //***************retryInterval **************/
  9585. c = 0;
  9586. loc = strstr(str, "retryInterval");
  9587. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9588. if(loc == NULL)
  9589. {
  9590. retryInterval=TRUE;
  9591. }
  9592. else
  9593. {
  9594. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9595. {
  9596. sstr[c] = loc[strlen("retryInterval")+2+c];
  9597. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9598. c++;
  9599. }
  9600. sstr[c] = '\0';
  9601. }
  9602. if(retryInterval==FALSE)
  9603. {
  9604. retryIntervalInt = atoi(sstr);
  9605. }
  9606. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9607. memset(path, 0, ARRAY_SIZE(path));
  9608. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9609. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9610. if(strncmp(locationstr,"http", 4) == 0)
  9611. {
  9612. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9613. protocol, host, path);
  9614. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9615. // protocol, user, password, host, path);
  9616. sprintf(ftppath,"/%s", path);
  9617. //DEBUG_INFO("protocol =%s\n",protocol);
  9618. //DEBUG_INFO("host =%s\n",host);
  9619. //DEBUG_INFO("path =%s\n",path);
  9620. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9621. int ftppathlen=strlen(ftppath);
  9622. int i=1;
  9623. char filenametemp[50];
  9624. while(i < ftppathlen)
  9625. {
  9626. int len=ftppathlen-i;
  9627. if(ftppath[len]== 47) // '/' ascll code: 47
  9628. {
  9629. DEBUG_INFO("compare '/' all right\n");
  9630. break;
  9631. }
  9632. i=i+1;
  9633. }
  9634. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9635. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9636. filenametemp[i+1] = 0;
  9637. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9638. do{
  9639. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9640. sleep(retryIntervalInt);
  9641. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9642. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9643. if(!isSuccess)
  9644. {
  9645. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9646. }
  9647. else
  9648. {
  9649. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9650. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9651. //isUpdateRequest = TRUE;
  9652. }
  9653. }
  9654. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9655. {
  9656. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9657. memset(temp, 0, ARRAY_SIZE(temp));
  9658. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9659. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9660. int ftppathlen=strlen(ftpbuf);
  9661. int i=1;
  9662. char filenametemp[50];
  9663. while(i < ftppathlen)
  9664. {
  9665. int len=ftppathlen-i;
  9666. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9667. {
  9668. DEBUG_INFO(" compare '/' all right\n");
  9669. break;
  9670. }
  9671. i=i+1;
  9672. }
  9673. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9674. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9675. filenametemp[i+1] = 0;
  9676. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9677. pch=strchr(temp,'@');
  9678. if(pch==NULL)
  9679. {
  9680. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9681. protocol, host, &port, path);
  9682. strcpy(user,"anonymous");
  9683. strcpy(password,"");
  9684. }
  9685. else
  9686. {
  9687. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9688. protocol, user, password, host, &port, path);
  9689. }
  9690. sscanf(host,"%[^/]%s",host1, path1);
  9691. sprintf(ftppath,"%s", path1);
  9692. //DEBUG_INFO("protocol =%s\n",protocol);
  9693. //DEBUG_INFO("user =%s\n",user);
  9694. //DEBUG_INFO("password =%s\n",password);
  9695. //DEBUG_INFO("host1 =%s\n",host1);
  9696. //DEBUG_INFO("port =%d\n",port);
  9697. //DEBUG_INFO("path1 =%s\n",path1);
  9698. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9699. //ftpFile(host, user, password, port, ftppath, fname);
  9700. //download firmware pthred
  9701. if(port == 0)
  9702. {
  9703. port = 21;
  9704. }
  9705. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9706. do{
  9707. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9708. sleep(retryIntervalInt);
  9709. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9710. if(!isSuccess)
  9711. {
  9712. //BulldogUtil.sleepMs(interval*1000);
  9713. DEBUG_INFO("Update firmware request and download file fail.\n");
  9714. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9715. }
  9716. else
  9717. {
  9718. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9719. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9720. //isUpdateRequest = TRUE;
  9721. }
  9722. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9723. }
  9724. else
  9725. {
  9726. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9727. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9728. }
  9729. pthread_exit(NULL);
  9730. }
  9731. //==========================================
  9732. // Handle server response routine
  9733. //==========================================
  9734. void handleAuthorizeResponse(char *payload, int gun_index)
  9735. {
  9736. mtrace();
  9737. char expiryDatestr[30]={0};
  9738. char parentIdTagstr[20]={0};
  9739. char statusstr[20]={0};
  9740. char expiryDatestrtemp[30]={0};
  9741. char parentIdTagstrtemp[20]={0};
  9742. char IdTagstrtemp[20]={0};
  9743. char statusstrtemp[20]={0};
  9744. int expiryDateISNULL=FALSE;
  9745. int parentIdTagISNULL=FALSE;
  9746. char sstr[160]={0};
  9747. char* filename = AuthorizationCache_JSON;
  9748. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9749. char *loc;
  9750. int resultRename=0;
  9751. int responseIdTagInfoAsZero= 0;
  9752. char rmFileCmd[50]={0};
  9753. DEBUG_INFO("handleAuthorizeResponse...\n");
  9754. json_object *Authorize;
  9755. Authorize = json_tokener_parse(payload);
  9756. if(!is_error(Authorize))
  9757. {
  9758. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9759. {
  9760. // Required data
  9761. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9762. // Optional data
  9763. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9764. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9765. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9766. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9767. }
  9768. }
  9769. json_object_put(Authorize);
  9770. if(expiryDateISNULL == FALSE)
  9771. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9772. if(parentIdTagISNULL == FALSE)
  9773. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9774. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9775. //Update idTag information to authorization cache if supproted
  9776. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9777. {
  9778. if((access(filename,F_OK))!=-1)
  9779. {
  9780. printf("AuthorizationCache exist.\n");
  9781. }
  9782. else
  9783. {
  9784. printf("AuthorizationCache not exist\n");
  9785. FILE *log = fopen(filename, "w+");
  9786. if(log == NULL)
  9787. {
  9788. printf("log is NULL\n");
  9789. goto out;
  9790. }
  9791. else
  9792. {
  9793. fclose(log);
  9794. }
  9795. }
  9796. FILE *infile;
  9797. FILE *outfile;
  9798. // open file for writing
  9799. infile = fopen (filename, "r");
  9800. outfile = fopen (tempfile, "w");
  9801. int c;
  9802. c = fgetc(infile);
  9803. //DEBUG_INFO("c:%d\n",c);
  9804. rewind(infile);
  9805. if(c == EOF)
  9806. {
  9807. DEBUG_INFO("Orignal File is NULL\n");
  9808. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9809. {
  9810. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9811. }
  9812. else
  9813. {
  9814. strcpy(expiryDatestrtemp, "");
  9815. }
  9816. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9817. {
  9818. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9819. }
  9820. else
  9821. {
  9822. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9823. }
  9824. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9825. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9826. fclose(infile);
  9827. fclose(outfile);
  9828. sprintf(rmFileCmd,"rm -f %s",filename);
  9829. system(rmFileCmd);
  9830. resultRename = rename(tempfile, filename);
  9831. if(resultRename == 0)
  9832. {
  9833. printf("File renamed successfully");
  9834. }
  9835. else
  9836. {
  9837. printf("Error: unable to rename the file");
  9838. }
  9839. }
  9840. else
  9841. {
  9842. char buf[160]={0};
  9843. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9844. {
  9845. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9846. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9847. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9848. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9849. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9850. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9851. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9852. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9853. //------------------IdTag-----------------------
  9854. loc = strstr(buf, "idTag");
  9855. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9856. c = 0;
  9857. while (loc[3+strlen("idTag")+c] != '\"')
  9858. {
  9859. sstr[c] = loc[3+strlen("idTag")+c];
  9860. c++;
  9861. }
  9862. sstr[c] = '\0';
  9863. strcpy(IdTagstrtemp,sstr);
  9864. //*********************expiryDate***************/
  9865. loc = strstr(buf, "expiryDate");
  9866. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9867. c = 0;
  9868. while (loc[3+strlen("expiryDate")+c] != '\"')
  9869. {
  9870. sstr[c] = loc[3+strlen("expiryDate")+c];
  9871. c++;
  9872. }
  9873. sstr[c] = '\0';
  9874. strcpy(expiryDatestr,sstr);
  9875. //*********************parentIdTag***************/
  9876. loc = strstr(buf, "parentIdTag");
  9877. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9878. c = 0;
  9879. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9880. {
  9881. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9882. c++;
  9883. }
  9884. sstr[c] = '\0';
  9885. strcpy(parentIdTagstr,sstr);
  9886. //*********************status***************/
  9887. loc = strstr(buf, "status");
  9888. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9889. c = 0;
  9890. while (loc[3+strlen("status")+c] != '\"')
  9891. {
  9892. sstr[c] = loc[3+strlen("status")+c];
  9893. c++;
  9894. }
  9895. sstr[c] = '\0';
  9896. strcpy(statusstr,sstr);
  9897. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9898. {
  9899. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9900. responseIdTagInfoAsZero = 1;
  9901. }
  9902. else
  9903. {
  9904. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9905. }
  9906. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9907. {
  9908. //modify item
  9909. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9910. {
  9911. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9912. }
  9913. else
  9914. {
  9915. strcpy(expiryDatestrtemp, "");
  9916. }
  9917. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9918. {
  9919. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9920. }
  9921. else
  9922. {
  9923. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9924. }
  9925. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9926. }
  9927. else
  9928. {
  9929. //wrie original item
  9930. strcpy(expiryDatestrtemp, expiryDatestr);
  9931. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9932. strcpy(statusstrtemp, statusstr);
  9933. }
  9934. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9935. }
  9936. fclose(infile);
  9937. fclose(outfile);
  9938. sprintf(rmFileCmd,"rm -f %s",filename);
  9939. system(rmFileCmd);
  9940. resultRename = rename(tempfile, filename);
  9941. if(resultRename == 0)
  9942. {
  9943. DEBUG_INFO("File renamed successfully");
  9944. }
  9945. else
  9946. {
  9947. DEBUG_INFO("Error: unable to rename the file");
  9948. }
  9949. }
  9950. }
  9951. out:
  9952. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9953. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9954. authorizeRetryTimes = 0;
  9955. }
  9956. char * strtrimc( char * s )
  9957. {
  9958. char * p1 = s;
  9959. char * p2 = s;
  9960. while(*p1 != '\0')
  9961. {
  9962. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9963. {
  9964. if(*p1 != ',')
  9965. {
  9966. p1 ++;
  9967. }
  9968. else
  9969. {
  9970. break;
  9971. }
  9972. }
  9973. if(*p1 != ',')
  9974. {
  9975. * p2 ++ = *p1 ++;
  9976. //printf("p2=%s\n",p2);
  9977. }
  9978. else
  9979. {
  9980. break;
  9981. }
  9982. }
  9983. *p2 = '\0';
  9984. return (s);
  9985. }
  9986. void handleBootNotificationResponse(char *payload, int gun_index)
  9987. {
  9988. mtrace();
  9989. char statusStr[12]={0};
  9990. char currentTimeStr[30]={0};
  9991. int intervalInt = 0;
  9992. struct tm tp;
  9993. char buf[28]={0};
  9994. char timebuf[50]={0};
  9995. DEBUG_INFO("handleBootNotificationResponse...\n");
  9996. json_object *BootNotification;
  9997. BootNotification = json_tokener_parse(payload);
  9998. if(!is_error(BootNotification))
  9999. {
  10000. // Required data
  10001. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10002. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10003. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10004. }
  10005. json_object_put(BootNotification);
  10006. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10007. BootNotificationInterval = intervalInt;
  10008. HeartBeatWaitTime = intervalInt;
  10009. //write back to ShmOCPP16Data->BootNotification
  10010. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10011. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10012. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10013. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10014. {
  10015. server_sign = TRUE;
  10016. server_pending =FALSE;
  10017. }
  10018. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10019. {
  10020. server_pending = TRUE;
  10021. }
  10022. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10023. tp.tm_isdst = -1;
  10024. //time_t utc = mktime(&tp);
  10025. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10026. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10027. sprintf(timebuf,"date -s '%s'",buf);
  10028. system(timebuf);
  10029. srand(time(NULL));
  10030. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10031. //==============================================
  10032. // RTC sync
  10033. //==============================================
  10034. system("/sbin/hwclock -w --systohc");
  10035. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10036. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10037. }
  10038. void handleDataTransferResponse(char *payload, int gun_index)
  10039. {
  10040. char sstr[160]={0};//sstr[200]={ 0 };
  10041. int c = 0;
  10042. char *loc;
  10043. DEBUG_INFO("handleDataTransferResponse ...\n");
  10044. loc = strstr(payload, "status");
  10045. printf("loc=%s\n",loc);
  10046. c = 0;
  10047. while (loc[3+strlen("status")+c] != '\"')
  10048. {
  10049. sstr[c] = loc[3+strlen("status")+c];
  10050. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10051. c++;
  10052. }
  10053. sstr[c] = '\0';
  10054. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10055. }
  10056. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10057. {
  10058. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10059. //struct json_object *obj;
  10060. // obj = json_tokener_parse(payload);
  10061. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10062. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10063. //No fields are defined.
  10064. }
  10065. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10066. {
  10067. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10068. //struct json_object *obj;
  10069. // obj = json_tokener_parse(payload);
  10070. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10071. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10072. //No fields are defined.
  10073. }
  10074. void handleHeartbeatResponse(char *payload, int gun_index)
  10075. {
  10076. mtrace();
  10077. struct tm tp;
  10078. char buf[28]={0};
  10079. char timebuf[50]={0};
  10080. DEBUG_INFO("handleHeartbeatResponse...\n");
  10081. json_object *Heartbeat;
  10082. Heartbeat = json_tokener_parse(payload);
  10083. if(!is_error(Heartbeat))
  10084. {
  10085. // Required data
  10086. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10087. }
  10088. json_object_put(BootNotification);
  10089. if(FirstHeartBeat == 0)
  10090. {
  10091. FirstHeartBeat = 1;
  10092. DEBUG_INFO("FirstHeartBeat \n");
  10093. }
  10094. HeartBeatWithNOResponse = 0;
  10095. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10096. tp.tm_isdst = -1;
  10097. //time_t utc = mktime(&tp);
  10098. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10099. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10100. sprintf(timebuf,"date -s '%s'",buf);
  10101. system(timebuf);
  10102. //==============================================
  10103. // RTC sync
  10104. //==============================================
  10105. system("/sbin/hwclock -w --systohc");
  10106. //===============================================
  10107. //Print Out HeartBeat log
  10108. //===============================================
  10109. {
  10110. double diff_t;
  10111. struct tm tp,tp1;
  10112. // BootNotification Receive Time
  10113. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10114. tp.tm_isdst = -1;
  10115. time_t BootNotificationReceiveTime = mktime(&tp);
  10116. //HeartBeat Receive Time
  10117. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10118. tp1.tm_isdst = -1;
  10119. time_t HeartBeatReceiveTime = mktime(&tp1);
  10120. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10121. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10122. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10123. {
  10124. HeartBeatCountPerHour = (int)diff_t / 3600;
  10125. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10126. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10127. }
  10128. }
  10129. }
  10130. void handleMeterValuesResponse(char *payload, int gun_index)
  10131. {
  10132. mtrace();
  10133. DEBUG_INFO("handleMeterValuesResponse...\n");
  10134. }
  10135. void handleStartTransactionResponse(char *payload, int gun_index)
  10136. {
  10137. mtrace();
  10138. //int transactionIdInt = 0;
  10139. FILE *outfile;
  10140. char data[100]={0};
  10141. DEBUG_INFO("handleStartTransactionResponse...\n");
  10142. json_object *StartTransaction;
  10143. StartTransaction = json_tokener_parse(payload);
  10144. if(!is_error(StartTransaction))
  10145. {
  10146. // Required data
  10147. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10148. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10149. // Optional data
  10150. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10151. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10152. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10153. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10154. }
  10155. json_object_put(StartTransaction);
  10156. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10157. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10158. //-----------Start : write to the Queue TransactionId file -----------------//
  10159. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10160. {}
  10161. else
  10162. {
  10163. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10164. if(log == NULL)
  10165. {
  10166. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10167. return ;
  10168. }
  10169. else
  10170. {
  10171. fclose(log);
  10172. }
  10173. }
  10174. // open file for writing
  10175. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10176. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10177. {
  10178. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10179. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10180. fputs(data, outfile);
  10181. fclose (outfile);
  10182. }
  10183. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10184. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10185. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10186. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10187. }
  10188. void handleStatusNotificationResponse(char *payload, int gun_index)
  10189. {
  10190. mtrace();
  10191. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10192. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10193. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10194. }
  10195. void handleStopTransactionnResponse(char *payload, int gun_index)
  10196. {
  10197. mtrace();
  10198. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10199. json_object *StopTransaction;
  10200. StopTransaction = json_tokener_parse(payload);
  10201. if(!is_error(StopTransaction))
  10202. {
  10203. // Optional data
  10204. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10205. {
  10206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10207. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10209. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10210. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10211. }
  10212. }
  10213. json_object_put(StopTransaction);
  10214. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10215. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10216. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10217. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10218. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10219. }
  10220. //==========================================
  10221. // Handle Error routine
  10222. //==========================================
  10223. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10224. {
  10225. mtrace();
  10226. #ifdef SystemLogMessage
  10227. DEBUG_INFO("errorCode: %s\n", errorCode);
  10228. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10229. DEBUG_INFO("errorDetails: %s\n", payload);
  10230. #endif
  10231. }
  10232. //===============================================
  10233. // Common routine
  10234. //===============================================
  10235. int initialConfigurationTable(void)
  10236. {
  10237. //clock_t start_t, end_t, total_t;
  10238. FILE *fp;
  10239. FILE *outfile;
  10240. char str[200]={0};
  10241. char sstr[100]={0};
  10242. int c = 0;
  10243. char *loc;
  10244. DEBUG_INFO("initialConfigurationTable...\n");
  10245. //start_t = clock();
  10246. //printf("Starting of the program, start_t = %ld\n", start_t);
  10247. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10248. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10249. {
  10250. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10251. if(outfile == NULL)
  10252. {
  10253. DEBUG_INFO("Error opening file\n");
  10254. return FALSE;
  10255. }
  10256. /*Core Profile*/
  10257. //AllowOfflineTxForUnknownId
  10258. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10259. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10263. //AuthorizationCacheEnabled
  10264. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10268. //AuthorizeRemoteTxRequests
  10269. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10273. //BlinkRepeat
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10278. //ClockAlignedDataInterval
  10279. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10283. //ConnectionTimeOut
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10288. //GetConfigurationMaxKeys
  10289. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10293. // HeartbeatInterval
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10298. // LightIntensity
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10303. // LocalAuthorizeOffline
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10308. // LocalPreAuthorize
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10313. // MaxEnergyOnInvalidId
  10314. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10317. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10319. // MeterValuesAlignedData
  10320. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10324. else
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10327. // MeterValuesAlignedDataMaxLength
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10332. else
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10335. // MeterValuesSampledData
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10338. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10340. else
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10343. // MeterValuesSampledDataMaxLength
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10348. else
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10351. // MeterValueSampleInterval
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10356. // MinimumStatusDuration
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10360. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10362. // NumberOfConnectors
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10366. {
  10367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10368. }
  10369. else
  10370. {
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10372. }
  10373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10374. // ResetRetries
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10379. // ConnectorPhaseRotation
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10384. // ConnectorPhaseRotationMaxLength
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10389. // StopTransactionOnEVSideDisconnect
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10394. // StopTransactionOnInvalidId
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10399. // StopTxnAlignedData
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10404. // StopTxnAlignedDataMaxLength
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10409. // StopTxnSampledData
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10414. else
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10417. // StopTxnSampledDataMaxLength
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10420. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10421. {
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10423. }
  10424. else
  10425. {
  10426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10427. }
  10428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10429. // SupportedFeatureProfiles
  10430. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10434. // SupportedFeatureProfilesMaxLength
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10439. // TransactionMessageAttempts
  10440. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10443. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10445. // TransactionMessageRetryInterval
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10449. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10451. // UnlockConnectorOnEVSideDisconnect
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10456. // WebSocketPingInterval
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10461. //* Local Auth List Management Profile*/
  10462. #if 0
  10463. //For OCTT Test Case
  10464. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10467. #endif
  10468. #if 1
  10469. //LocalAuthListEnabled
  10470. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10474. #endif
  10475. //LocalAuthListMaxLength
  10476. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10480. //SendLocalListMaxLength
  10481. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10485. //ReserveConnectorZeroSupported
  10486. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10490. //* Smart Charging Profile */
  10491. //ChargeProfileMaxStackLevel
  10492. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10496. // ChargingScheduleAllowedChargingRateUnit
  10497. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10501. // ChargingScheduleMaxPeriods
  10502. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10506. // ConnectorSwitch3to1PhaseSupported
  10507. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10511. // MaxChargingProfilesInstalled
  10512. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10516. fclose(outfile);
  10517. }
  10518. else
  10519. {
  10520. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10521. char keystr[60]={0};
  10522. char readonlystr[10]={0};
  10523. char valuestr[100]={0};
  10524. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10525. if(fp == NULL) {
  10526. DEBUG_INFO("Error opening file");
  10527. return FALSE;
  10528. }
  10529. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10530. {
  10531. //DEBUG_INFO("Get Configuration \n");
  10532. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10533. //*************************key*********************************/
  10534. loc = strstr(str, "key");
  10535. c = 0;
  10536. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10537. while (loc[strlen("key")+3+c] != '\"')
  10538. {
  10539. sstr[c] = loc[strlen("key")+3+c];
  10540. c++;
  10541. }
  10542. sstr[c] = '\0';
  10543. strcpy(keystr,sstr);
  10544. //*************************readonly*********************************/
  10545. loc = strstr(str, "readonly");
  10546. c = 0;
  10547. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10548. while (loc[strlen("readonly")+2+c] != ',')
  10549. {
  10550. sstr[c] = loc[strlen("readonly")+2+c];
  10551. c++;
  10552. }
  10553. sstr[c] = '\0';
  10554. strcpy(readonlystr,sstr);
  10555. //*************************value*********************************/
  10556. loc = strstr(str, "value");
  10557. c = 0;
  10558. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10559. while (loc[strlen("value")+3+c] != '\"')
  10560. {
  10561. sstr[c] = loc[strlen("value")+3+c];
  10562. c++;
  10563. }
  10564. sstr[c] = '\0';
  10565. strcpy(valuestr,sstr);
  10566. // DEBUG_INFO("keystr=%s\n",keystr);
  10567. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10568. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10569. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10570. {
  10571. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10574. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10575. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10576. }
  10577. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10578. {
  10579. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10582. }
  10583. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10584. {
  10585. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10587. }
  10588. if(strcmp(keystr, "BlinkRepeat") == 0)
  10589. {
  10590. //Charger.BlinkRepeat = Integer.parseInt(value);
  10591. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10593. }
  10594. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10595. {
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10598. }
  10599. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10600. {
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10603. }
  10604. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10605. {
  10606. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10608. }
  10609. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10610. {
  10611. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10613. HeartBeatWaitTime = atoi(valuestr);
  10614. }
  10615. if(strcmp(keystr, "LightIntensity") == 0)
  10616. {
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10619. }
  10620. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10621. {
  10622. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10624. }
  10625. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10626. {
  10627. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10629. }
  10630. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10631. {
  10632. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10634. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10635. }
  10636. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10637. {
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10640. }
  10641. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10642. {
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10645. }
  10646. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10647. {
  10648. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10650. }
  10651. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10652. {
  10653. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10655. }
  10656. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10657. {
  10658. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10660. }
  10661. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10662. {
  10663. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10665. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10666. }
  10667. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10668. {
  10669. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10671. }
  10672. if(strcmp(keystr, "ResetRetries") == 0)
  10673. {
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10676. }
  10677. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10678. {
  10679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10681. }
  10682. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10683. {
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10686. }
  10687. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10688. {
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10691. }
  10692. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10693. {
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10696. }
  10697. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10698. {
  10699. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10701. }
  10702. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10703. {
  10704. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10706. }
  10707. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10708. {
  10709. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10711. }
  10712. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10713. {
  10714. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10716. }
  10717. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10718. {
  10719. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10721. }
  10722. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10723. {
  10724. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10726. }
  10727. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10728. {
  10729. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10731. TransactionMessageAttemptsValue = atoi(valuestr);
  10732. }
  10733. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10734. {
  10735. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10737. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10738. }
  10739. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10740. {
  10741. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10743. }
  10744. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10745. {
  10746. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10748. }
  10749. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10750. {
  10751. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10753. }
  10754. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10755. {
  10756. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10758. }
  10759. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10760. {
  10761. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10763. }
  10764. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10765. {
  10766. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10768. }
  10769. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10770. {
  10771. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10773. }
  10774. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10775. {
  10776. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10778. }
  10779. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10780. {
  10781. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10783. }
  10784. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10785. {
  10786. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10788. }
  10789. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10790. {
  10791. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10793. }
  10794. }
  10795. fclose(fp);
  10796. }
  10797. return 0;
  10798. }
  10799. void StoreConfigurationTable(void)
  10800. {
  10801. FILE *outfile;
  10802. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10803. if(outfile == NULL)
  10804. {
  10805. DEBUG_INFO("Error opening file");
  10806. return ;
  10807. }
  10808. /*Core Profile*/
  10809. //AllowOfflineTxForUnknownId
  10810. /*
  10811. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10812. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10815. */
  10816. //DEBUG_INFO("data=%s\n",data);
  10817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10818. //AuthorizationCacheEnabled
  10819. /*
  10820. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10823. */
  10824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10825. //AuthorizeRemoteTxRequests
  10826. /*
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10830. */
  10831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10832. //BlinkRepeat
  10833. /*
  10834. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10837. */
  10838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10839. //ClockAlignedDataInterval
  10840. /*
  10841. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10844. */
  10845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10846. //ConnectionTimeOut
  10847. /*
  10848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10851. */
  10852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10853. //GetConfigurationMaxKeys
  10854. /*
  10855. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10858. */
  10859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10860. // HeartbeatInterval
  10861. /*
  10862. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10865. */
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10867. // LightIntensity
  10868. /*
  10869. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10872. */
  10873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10874. // LocalAuthorizeOffline
  10875. /*
  10876. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10879. */
  10880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10881. // LocalPreAuthorize
  10882. /*
  10883. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10886. */
  10887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10888. // MaxEnergyOnInvalidId
  10889. /*
  10890. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10893. */
  10894. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10896. // MeterValuesAlignedData
  10897. /*
  10898. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10901. */
  10902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10903. // MeterValuesAlignedDataMaxLength
  10904. /*
  10905. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10908. */
  10909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10910. // MeterValuesSampledData
  10911. /*
  10912. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10915. */
  10916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10917. // MeterValuesSampledDataMaxLength
  10918. /*
  10919. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10922. */
  10923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10924. // MeterValueSampleInterval
  10925. /*
  10926. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10929. */
  10930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10931. // MinimumStatusDuration
  10932. /*
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10936. */
  10937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10938. // NumberOfConnectors
  10939. /*
  10940. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10943. {
  10944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10945. }
  10946. else
  10947. {
  10948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10949. }
  10950. */
  10951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10952. // ResetRetries
  10953. /*
  10954. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10957. */
  10958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10959. // ConnectorPhaseRotation
  10960. /*
  10961. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10964. */
  10965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10966. // ConnectorPhaseRotationMaxLength
  10967. /*
  10968. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10971. */
  10972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10973. // StopTransactionOnEVSideDisconnect
  10974. /*
  10975. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10978. */
  10979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10980. // StopTransactionOnInvalidId
  10981. /*
  10982. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10985. */
  10986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10987. // StopTxnAlignedData
  10988. /*
  10989. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10992. */
  10993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10994. // StopTxnAlignedDataMaxLength
  10995. /*
  10996. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10999. */
  11000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11001. // StopTxnSampledData
  11002. /*
  11003. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11006. */
  11007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11008. // StopTxnSampledDataMaxLength
  11009. /*
  11010. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11013. */
  11014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11015. // SupportedFeatureProfiles
  11016. /*
  11017. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11020. */
  11021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11022. // SupportedFeatureProfilesMaxLength
  11023. /*
  11024. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11027. */
  11028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11029. // TransactionMessageAttempts
  11030. /*
  11031. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11034. */
  11035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11036. // TransactionMessageRetryInterval
  11037. /*
  11038. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11041. */
  11042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11043. // UnlockConnectorOnEVSideDisconnect
  11044. /*
  11045. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11048. */
  11049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11050. // WebSocketPingInterval
  11051. /*
  11052. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11055. */
  11056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11057. //* Local Auth List Management Profile*/
  11058. //LocalAuthListEnabled
  11059. /*
  11060. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11063. */
  11064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11065. //LocalAuthListMaxLength
  11066. /*
  11067. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11070. */
  11071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11072. //SendLocalListMaxLength
  11073. /*
  11074. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11077. */
  11078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11079. //ReserveConnectorZeroSupported
  11080. /*
  11081. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11084. */
  11085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11086. //* Smart Charging Profile */
  11087. //ChargeProfileMaxStackLevel
  11088. /*
  11089. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11092. */
  11093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11094. // ChargingScheduleAllowedChargingRateUnit
  11095. /*
  11096. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11099. */
  11100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11101. // ChargingScheduleMaxPeriods
  11102. /*
  11103. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11106. */
  11107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11108. // ConnectorSwitch3to1PhaseSupported
  11109. /*
  11110. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11113. */
  11114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11115. // MaxChargingProfilesInstalled
  11116. /*
  11117. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11120. */
  11121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11122. fclose(outfile);
  11123. }
  11124. void getKeyValue(char *keyReq)
  11125. {
  11126. int isEmpty = FALSE;
  11127. int isKnowKey = FALSE;
  11128. DEBUG_INFO("keyReq = %s\n", keyReq);
  11129. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11130. isEmpty = TRUE;
  11131. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11138. }
  11139. else
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11142. }
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11144. isKnowKey = TRUE;
  11145. }
  11146. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11153. }
  11154. else
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11157. }
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11159. isKnowKey = TRUE;
  11160. }
  11161. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11168. }
  11169. else
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11172. }
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11174. isKnowKey = TRUE;
  11175. }
  11176. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11183. }
  11184. else
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11187. }
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11189. isKnowKey = TRUE;
  11190. }
  11191. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11198. }
  11199. else
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11202. }
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11279. isKnowKey = TRUE;
  11280. }
  11281. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11288. }
  11289. else
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11292. }
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11294. isKnowKey = TRUE;
  11295. }
  11296. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11303. }
  11304. else
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11307. }
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11309. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11310. isKnowKey = TRUE;
  11311. }
  11312. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11319. }
  11320. else
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11323. }
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11325. isKnowKey = TRUE;
  11326. }
  11327. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11334. }
  11335. else
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11338. }
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11340. isKnowKey = TRUE;
  11341. }
  11342. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11349. }
  11350. else
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11353. }
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11355. isKnowKey = TRUE;
  11356. }
  11357. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11364. }
  11365. else
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11368. }
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11370. isKnowKey = TRUE;
  11371. }
  11372. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11379. }
  11380. else
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11383. }
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11385. isKnowKey = TRUE;
  11386. }
  11387. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11394. }
  11395. else
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11398. }
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11400. isKnowKey = TRUE;
  11401. }
  11402. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11409. }
  11410. else
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11413. }
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11415. isKnowKey = TRUE;
  11416. }
  11417. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11424. }
  11425. else
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11428. }
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11430. isKnowKey = TRUE;
  11431. }
  11432. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11439. }
  11440. else
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11443. }
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11445. isKnowKey = TRUE;
  11446. }
  11447. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11454. }
  11455. else
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11458. }
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11460. isKnowKey = TRUE;
  11461. }
  11462. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11463. {
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11469. }
  11470. else
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11473. }
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11475. isKnowKey = TRUE;
  11476. }
  11477. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11478. {
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11484. }
  11485. else
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11488. }
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11490. isKnowKey = TRUE;
  11491. }
  11492. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11493. {
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11497. {
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11499. }
  11500. else
  11501. {
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11503. }
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11505. isKnowKey = TRUE;
  11506. }
  11507. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11508. {
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11512. {
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11514. }
  11515. else
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11518. }
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11520. isKnowKey = TRUE;
  11521. }
  11522. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11523. {
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11529. }
  11530. else
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11533. }
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11535. isKnowKey = TRUE;
  11536. }
  11537. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11544. }
  11545. else
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11548. }
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11550. isKnowKey = TRUE;
  11551. }
  11552. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11559. }
  11560. else
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11563. }
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11565. isKnowKey = TRUE;
  11566. }
  11567. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11574. }
  11575. else
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11578. }
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11580. isKnowKey = TRUE;
  11581. }
  11582. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11589. }
  11590. else
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11593. }
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11595. isKnowKey = TRUE;
  11596. }
  11597. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11604. }
  11605. else
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11608. }
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11610. isKnowKey = TRUE;
  11611. }
  11612. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11619. }
  11620. else
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11623. }
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11625. isKnowKey = TRUE;
  11626. }
  11627. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11634. }
  11635. else
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11638. }
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11640. isKnowKey = TRUE;
  11641. }
  11642. #if 1
  11643. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11644. {
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11647. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11650. }
  11651. else
  11652. {
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11654. }
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11656. isKnowKey = TRUE;
  11657. }
  11658. #endif
  11659. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11660. {
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11663. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11666. }
  11667. else
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11670. }
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11672. isKnowKey = TRUE;
  11673. }
  11674. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11678. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11681. }
  11682. else
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11685. }
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11687. isKnowKey = TRUE;
  11688. }
  11689. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11693. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11696. }
  11697. else
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11700. }
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11702. isKnowKey = TRUE;
  11703. }
  11704. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11708. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11709. {
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11711. }
  11712. else
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11715. }
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11717. isKnowKey = TRUE;
  11718. }
  11719. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11723. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11726. }
  11727. else
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11730. }
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11732. isKnowKey = TRUE;
  11733. }
  11734. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11738. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11741. }
  11742. else
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11745. }
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11747. isKnowKey = TRUE;
  11748. }
  11749. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11754. {
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11756. }
  11757. else
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11760. }
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11762. isKnowKey = TRUE;
  11763. }
  11764. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11768. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11769. {
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11771. }
  11772. else
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11775. }
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11777. isKnowKey = TRUE;
  11778. }
  11779. //=========================================================
  11780. if(!isEmpty && !isKnowKey)
  11781. {
  11782. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11783. strcpy(unknownkey[UnknownKeynum], keyReq);
  11784. UnknownKeynum = UnknownKeynum + 1;
  11785. }
  11786. }
  11787. void processUnkownKey(void)
  11788. {
  11789. DEBUG_INFO("processUnkownKey...\n");
  11790. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11791. for(int index=0; index < UnknownKeynum; index++)
  11792. {
  11793. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11794. {
  11795. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11796. }
  11797. }
  11798. }
  11799. int setKeyValue(char *key, char *value)
  11800. {
  11801. int isSuccess = NotSupported;
  11802. int check_ascii=0;
  11803. char str[10]={0};
  11804. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11805. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11806. {
  11807. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11809. {
  11810. strcpy(str, (const char*)value);
  11811. for(int i = 0; str[i]; i++){
  11812. str[i] = tolower(str[i]);
  11813. }
  11814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11815. isSuccess = ConfigurationStatus_Accepted;
  11816. }
  11817. else
  11818. {
  11819. isSuccess = ConfigurationStatus_Rejected;
  11820. }
  11821. }
  11822. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11823. {
  11824. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11826. {
  11827. strcpy(str, (const char*)value);
  11828. for(int i = 0; str[i]; i++){
  11829. str[i] = tolower(str[i]);
  11830. }
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11834. }
  11835. else
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. }
  11840. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11841. {
  11842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11843. {
  11844. strcpy(str, (const char*)value);
  11845. for(int i = 0; str[i]; i++)
  11846. {
  11847. str[i] = tolower(str[i]);
  11848. }
  11849. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11851. isSuccess = ConfigurationStatus_Accepted;
  11852. }
  11853. else
  11854. {
  11855. isSuccess = ConfigurationStatus_Rejected;
  11856. }
  11857. }
  11858. if(strcmp(key, "BlinkRepeat") == 0)
  11859. {
  11860. //Charger.BlinkRepeat = Integer.parseInt(value);
  11861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11862. {
  11863. check_ascii = value[0];
  11864. if( (check_ascii < 48) || (check_ascii > 57) )
  11865. {
  11866. isSuccess = ConfigurationStatus_Rejected;
  11867. }
  11868. else
  11869. {
  11870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11871. isSuccess = ConfigurationStatus_Accepted;
  11872. }
  11873. }
  11874. else
  11875. {
  11876. isSuccess = ConfigurationStatus_Rejected;
  11877. }
  11878. }
  11879. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11880. {
  11881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11882. {
  11883. check_ascii = value[0];
  11884. if( (check_ascii < 48) || (check_ascii > 57) )
  11885. {
  11886. isSuccess = ConfigurationStatus_Rejected;
  11887. }
  11888. else
  11889. {
  11890. if((atoi(value) == 0) || (atoi(value) >= 10))
  11891. {
  11892. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11894. isSuccess = ConfigurationStatus_Accepted;
  11895. }
  11896. else
  11897. isSuccess = ConfigurationStatus_Rejected;
  11898. }
  11899. }
  11900. else
  11901. {
  11902. isSuccess = ConfigurationStatus_Rejected;
  11903. }
  11904. }
  11905. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11906. {
  11907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11908. {
  11909. check_ascii = value[0];
  11910. if( (check_ascii < 48) || (check_ascii > 57) )
  11911. {
  11912. isSuccess = ConfigurationStatus_Rejected;
  11913. }
  11914. else
  11915. {
  11916. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11918. isSuccess = ConfigurationStatus_Accepted;
  11919. }
  11920. }
  11921. else
  11922. {
  11923. isSuccess = ConfigurationStatus_Rejected;
  11924. }
  11925. }
  11926. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11927. {
  11928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11929. {
  11930. check_ascii = value[0];
  11931. if( (check_ascii < 48) || (check_ascii > 57) )
  11932. {
  11933. isSuccess = ConfigurationStatus_Rejected;
  11934. }
  11935. else
  11936. {
  11937. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11939. isSuccess = ConfigurationStatus_Accepted;
  11940. }
  11941. }
  11942. else
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. }
  11947. if(strcmp(key, "HeartbeatInterval") == 0)
  11948. {
  11949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11950. {
  11951. check_ascii = value[0];
  11952. if( (check_ascii < 48) || (check_ascii > 57) )
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. else
  11957. {
  11958. if((atoi(value) == 0) || (atoi(value) >= 10))
  11959. {
  11960. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11962. HeartBeatWaitTime = atoi(value);
  11963. isSuccess = ConfigurationStatus_Accepted;
  11964. }
  11965. else
  11966. {
  11967. isSuccess = ConfigurationStatus_Rejected;
  11968. }
  11969. }
  11970. }
  11971. else
  11972. {
  11973. isSuccess = ConfigurationStatus_Rejected;
  11974. }
  11975. }
  11976. if(strcmp(key, "LightIntensity") == 0)
  11977. {
  11978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11979. {
  11980. check_ascii = value[0];
  11981. if( (check_ascii < 48) || (check_ascii > 57) )
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. else
  11986. {
  11987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11988. isSuccess = ConfigurationStatus_Accepted;
  11989. }
  11990. }
  11991. else
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. }
  11996. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11997. {
  11998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11999. {
  12000. strcpy(str, (const char*)value);
  12001. for(int i = 0; str[i]; i++)
  12002. {
  12003. str[i] = tolower(str[i]);
  12004. }
  12005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12006. isSuccess = ConfigurationStatus_Accepted;
  12007. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12008. }
  12009. else
  12010. {
  12011. isSuccess = ConfigurationStatus_Rejected;
  12012. }
  12013. }
  12014. if(strcmp(key, "LocalPreAuthorize") == 0)
  12015. {
  12016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12017. {
  12018. strcpy(str, (const char*)value);
  12019. for(int i = 0; str[i]; i++)
  12020. {
  12021. str[i] = tolower(str[i]);
  12022. }
  12023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12024. isSuccess = ConfigurationStatus_Accepted;
  12025. }
  12026. else
  12027. {
  12028. isSuccess = ConfigurationStatus_Rejected;
  12029. }
  12030. }
  12031. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12032. {
  12033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12034. {
  12035. check_ascii = value[0];
  12036. if( (check_ascii < 48) || (check_ascii > 57) )
  12037. {
  12038. isSuccess = ConfigurationStatus_Rejected;
  12039. }
  12040. else
  12041. {
  12042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12043. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12044. isSuccess = ConfigurationStatus_Accepted;
  12045. }
  12046. }
  12047. else
  12048. {
  12049. isSuccess = ConfigurationStatus_Rejected;
  12050. }
  12051. }
  12052. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12053. {
  12054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12055. {
  12056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12057. isSuccess = ConfigurationStatus_Accepted;
  12058. }
  12059. else
  12060. {
  12061. isSuccess = ConfigurationStatus_Rejected;
  12062. }
  12063. }
  12064. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12065. {
  12066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12067. {
  12068. check_ascii = value[0];
  12069. if( (check_ascii < 48) || (check_ascii > 57) )
  12070. {
  12071. isSuccess = ConfigurationStatus_Rejected;
  12072. }
  12073. else
  12074. {
  12075. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12077. isSuccess = ConfigurationStatus_Accepted;
  12078. }
  12079. }
  12080. else
  12081. {
  12082. isSuccess = ConfigurationStatus_Rejected;
  12083. }
  12084. }
  12085. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12086. {
  12087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12088. {
  12089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12090. isSuccess = ConfigurationStatus_Accepted;
  12091. }
  12092. else
  12093. {
  12094. isSuccess = ConfigurationStatus_Rejected;
  12095. }
  12096. }
  12097. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12098. {
  12099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12100. {
  12101. check_ascii = value[0];
  12102. if( (check_ascii < 48) || (check_ascii > 57) )
  12103. {
  12104. isSuccess = ConfigurationStatus_Rejected;
  12105. }
  12106. else
  12107. {
  12108. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12110. isSuccess = ConfigurationStatus_Accepted;
  12111. }
  12112. }
  12113. else
  12114. {
  12115. isSuccess = ConfigurationStatus_Rejected;
  12116. }
  12117. }
  12118. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12119. {
  12120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12121. {
  12122. check_ascii = value[0];
  12123. if( (check_ascii < 48) || (check_ascii > 57) )
  12124. {
  12125. isSuccess = ConfigurationStatus_Rejected;
  12126. }
  12127. else
  12128. {
  12129. if((atoi(value) == 0) || (atoi(value) >= 10))
  12130. {
  12131. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12133. isSuccess = ConfigurationStatus_Accepted;
  12134. }
  12135. else
  12136. {
  12137. isSuccess = ConfigurationStatus_Rejected;
  12138. }
  12139. }
  12140. }
  12141. else
  12142. {
  12143. isSuccess = ConfigurationStatus_Rejected;
  12144. }
  12145. }
  12146. if(strcmp(key, "MinimumStatusDuration") == 0)
  12147. {
  12148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12149. {
  12150. check_ascii = value[0];
  12151. if( (check_ascii < 48) || (check_ascii > 57) )
  12152. {
  12153. isSuccess = ConfigurationStatus_Rejected;
  12154. }
  12155. else
  12156. {
  12157. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12158. {
  12159. isSuccess = ConfigurationStatus_Rejected;
  12160. }
  12161. else
  12162. {
  12163. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12165. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12166. isSuccess = ConfigurationStatus_Accepted;
  12167. }
  12168. }
  12169. }
  12170. else
  12171. {
  12172. isSuccess = ConfigurationStatus_Rejected;
  12173. }
  12174. }
  12175. if(strcmp(key, "NumberOfConnectors") == 0)
  12176. {
  12177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12178. {
  12179. check_ascii = value[0];
  12180. if( (check_ascii < 48) || (check_ascii > 57) )
  12181. {
  12182. isSuccess = ConfigurationStatus_Rejected;
  12183. }
  12184. else
  12185. {
  12186. //Charger.ResetRetries = Integer.parseInt(value);
  12187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12188. isSuccess = ConfigurationStatus_Accepted;
  12189. }
  12190. }
  12191. else
  12192. {
  12193. isSuccess = ConfigurationStatus_Rejected;
  12194. }
  12195. }
  12196. if(strcmp(key, "ResetRetries") == 0)
  12197. {
  12198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12199. {
  12200. check_ascii = value[0];
  12201. if( (check_ascii < 48) || (check_ascii > 57) )
  12202. {
  12203. isSuccess = ConfigurationStatus_Rejected;
  12204. }
  12205. else
  12206. {
  12207. //Charger.ResetRetries = Integer.parseInt(value);
  12208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12209. isSuccess = ConfigurationStatus_Accepted;
  12210. }
  12211. }
  12212. else
  12213. {
  12214. isSuccess = ConfigurationStatus_Rejected;
  12215. }
  12216. }
  12217. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12218. {
  12219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12220. {
  12221. strcpy(str, (const char*)value);
  12222. for(int i = 0; str[i]; i++)
  12223. {
  12224. str[i] = tolower(str[i]);
  12225. }
  12226. if(strcmp(str, "notapplicable")== 0)
  12227. {
  12228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12229. isSuccess = ConfigurationStatus_Accepted;
  12230. }
  12231. else if(strcmp(str, "unknown")== 0)
  12232. {
  12233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12234. isSuccess = ConfigurationStatus_Accepted;
  12235. }
  12236. else if(strcmp(str, "rst")== 0)
  12237. {
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. else if(strcmp(str, "rts")== 0)
  12242. {
  12243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12244. isSuccess = ConfigurationStatus_Accepted;
  12245. }
  12246. else if(strcmp(str, "srt")== 0)
  12247. {
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12249. isSuccess = ConfigurationStatus_Accepted;
  12250. }
  12251. else if(strcmp(str, "str")== 0)
  12252. {
  12253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12254. isSuccess = ConfigurationStatus_Accepted;
  12255. }
  12256. else if(strcmp(str, "trs")== 0)
  12257. {
  12258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12259. isSuccess = ConfigurationStatus_Accepted;
  12260. }
  12261. else if(strcmp(str, "tsr")== 0)
  12262. {
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12264. isSuccess = ConfigurationStatus_Accepted;
  12265. }
  12266. else
  12267. {
  12268. isSuccess = ConfigurationStatus_Rejected;
  12269. }
  12270. }
  12271. else
  12272. {
  12273. isSuccess = ConfigurationStatus_Rejected;
  12274. }
  12275. }
  12276. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12277. {
  12278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12279. {
  12280. check_ascii = value[0];
  12281. if( (check_ascii < 48) || (check_ascii > 57) )
  12282. {
  12283. isSuccess = ConfigurationStatus_Rejected;
  12284. }
  12285. else
  12286. {
  12287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12288. isSuccess = ConfigurationStatus_Accepted;
  12289. }
  12290. }
  12291. else
  12292. {
  12293. isSuccess = ConfigurationStatus_Rejected;
  12294. }
  12295. }
  12296. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12297. {
  12298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12299. {
  12300. strcpy(str, (const char*)value);
  12301. for(int i = 0; str[i]; i++)
  12302. {
  12303. str[i] = tolower(str[i]);
  12304. }
  12305. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12307. isSuccess = ConfigurationStatus_Accepted;
  12308. }
  12309. else
  12310. {
  12311. isSuccess = ConfigurationStatus_Rejected;
  12312. }
  12313. }
  12314. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12315. {
  12316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12317. {
  12318. strcpy(str, (const char*)value);
  12319. for(int i = 0; str[i]; i++)
  12320. {
  12321. str[i] = tolower(str[i]);
  12322. }
  12323. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12325. isSuccess = ConfigurationStatus_Accepted;
  12326. }
  12327. else
  12328. {
  12329. isSuccess = ConfigurationStatus_Rejected;
  12330. }
  12331. }
  12332. if(strcmp(key, "StopTxnAlignedData") == 0)
  12333. {
  12334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12335. {
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12337. isSuccess = ConfigurationStatus_Accepted;
  12338. }
  12339. else
  12340. {
  12341. isSuccess = ConfigurationStatus_Rejected;
  12342. }
  12343. }
  12344. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12345. {
  12346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12347. {
  12348. check_ascii = value[0];
  12349. if( (check_ascii < 48) || (check_ascii > 57) )
  12350. {
  12351. isSuccess = ConfigurationStatus_Rejected;
  12352. }
  12353. else
  12354. {
  12355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12356. isSuccess = ConfigurationStatus_Accepted;
  12357. }
  12358. }
  12359. else
  12360. {
  12361. isSuccess = ConfigurationStatus_Rejected;
  12362. }
  12363. }
  12364. if(strcmp(key, "StopTxnSampledData") == 0)
  12365. {
  12366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12367. {
  12368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12369. isSuccess = ConfigurationStatus_Accepted;
  12370. }
  12371. else
  12372. {
  12373. isSuccess = ConfigurationStatus_Rejected;
  12374. }
  12375. }
  12376. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12377. {
  12378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12379. {
  12380. check_ascii = value[0];
  12381. if( (check_ascii < 48) || (check_ascii > 57) )
  12382. {
  12383. isSuccess = ConfigurationStatus_Rejected;
  12384. }
  12385. else
  12386. {
  12387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12388. isSuccess = ConfigurationStatus_Accepted;
  12389. }
  12390. }
  12391. else
  12392. {
  12393. isSuccess = ConfigurationStatus_Rejected;
  12394. }
  12395. }
  12396. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12397. {
  12398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12399. {
  12400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12401. isSuccess = ConfigurationStatus_Accepted;
  12402. }
  12403. else
  12404. {
  12405. isSuccess = ConfigurationStatus_Rejected;
  12406. }
  12407. }
  12408. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12409. {
  12410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12411. {
  12412. check_ascii = value[0];
  12413. if( (check_ascii < 48) || (check_ascii > 57) )
  12414. {
  12415. isSuccess = ConfigurationStatus_Rejected;
  12416. }
  12417. else
  12418. {
  12419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12420. isSuccess = ConfigurationStatus_Accepted;
  12421. }
  12422. }
  12423. else
  12424. {
  12425. isSuccess = ConfigurationStatus_Rejected;
  12426. }
  12427. }
  12428. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12429. {
  12430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12431. {
  12432. check_ascii = value[0];
  12433. if( (check_ascii < 48) || (check_ascii > 57) )
  12434. {
  12435. isSuccess = ConfigurationStatus_Rejected;
  12436. }
  12437. else
  12438. {
  12439. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12441. TransactionMessageAttemptsValue = atoi(value);
  12442. isSuccess = ConfigurationStatus_Accepted;
  12443. }
  12444. }
  12445. else
  12446. {
  12447. isSuccess = ConfigurationStatus_Rejected;
  12448. }
  12449. }
  12450. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12451. {
  12452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12453. {
  12454. check_ascii = value[0];
  12455. if( (check_ascii < 48) || (check_ascii > 57) )
  12456. {
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. else
  12460. {
  12461. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12463. TransactionMessageRetryIntervalValue = atoi(value);
  12464. isSuccess = ConfigurationStatus_Accepted;
  12465. }
  12466. }
  12467. else
  12468. {
  12469. isSuccess = ConfigurationStatus_Rejected;
  12470. }
  12471. }
  12472. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12473. {
  12474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12475. {
  12476. strcpy(str, (const char*)value);
  12477. for(int i = 0; str[i]; i++)
  12478. {
  12479. str[i] = tolower(str[i]);
  12480. }
  12481. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12483. isSuccess = ConfigurationStatus_Accepted;
  12484. }
  12485. else
  12486. {
  12487. isSuccess = ConfigurationStatus_Rejected;
  12488. }
  12489. }
  12490. if(strcmp(key, "WebSocketPingInterval") == 0)
  12491. {
  12492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12493. {
  12494. check_ascii = value[0];
  12495. if( (check_ascii < 48) || (check_ascii > 57) )
  12496. {
  12497. isSuccess = ConfigurationStatus_Rejected;
  12498. }
  12499. else
  12500. {
  12501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12502. isSuccess = ConfigurationStatus_Accepted;
  12503. }
  12504. }
  12505. else
  12506. {
  12507. isSuccess = ConfigurationStatus_Rejected;
  12508. }
  12509. }
  12510. #if 0
  12511. //For OCPP Test Case
  12512. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12513. {
  12514. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12515. {
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12517. isSuccess = ConfigurationStatus_Accepted;
  12518. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12519. }
  12520. else
  12521. {
  12522. isSuccess = ConfigurationStatus_Rejected;
  12523. }
  12524. }
  12525. #endif
  12526. #if 1
  12527. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12528. {
  12529. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12530. {
  12531. strcpy(str, (const char*)value);
  12532. for(int i = 0; str[i]; i++)
  12533. {
  12534. str[i] = tolower(str[i]);
  12535. }
  12536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12537. isSuccess = ConfigurationStatus_Accepted;
  12538. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12539. }
  12540. else
  12541. {
  12542. isSuccess = ConfigurationStatus_Rejected;
  12543. }
  12544. }
  12545. #endif
  12546. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12547. {
  12548. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12549. {
  12550. check_ascii = value[0];
  12551. if( (check_ascii < 48) || (check_ascii > 57) )
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. else
  12556. {
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12558. isSuccess = ConfigurationStatus_Accepted;
  12559. }
  12560. }
  12561. else
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. }
  12566. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12567. {
  12568. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12569. {
  12570. check_ascii = value[0];
  12571. if( (check_ascii < 48) || (check_ascii > 57) )
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. else
  12576. {
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12578. isSuccess = ConfigurationStatus_Accepted;
  12579. }
  12580. }
  12581. else
  12582. {
  12583. isSuccess = ConfigurationStatus_Rejected;
  12584. }
  12585. }
  12586. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12587. {
  12588. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12589. {
  12590. strcpy(str, (const char*)value);
  12591. for(int i = 0; str[i]; i++)
  12592. {
  12593. str[i] = tolower(str[i]);
  12594. }
  12595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12596. isSuccess = ConfigurationStatus_Accepted;
  12597. }
  12598. else
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. }
  12603. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12604. {
  12605. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12606. {
  12607. check_ascii = value[0];
  12608. if( (check_ascii < 48) || (check_ascii > 57) )
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. else
  12613. {
  12614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12615. isSuccess = ConfigurationStatus_Accepted;
  12616. }
  12617. }
  12618. else
  12619. {
  12620. isSuccess = ConfigurationStatus_Rejected;
  12621. }
  12622. }
  12623. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12624. {
  12625. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12626. {
  12627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12628. isSuccess = ConfigurationStatus_Accepted;
  12629. }
  12630. else
  12631. {
  12632. isSuccess = ConfigurationStatus_Rejected;
  12633. }
  12634. }
  12635. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12636. {
  12637. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12638. {
  12639. check_ascii = value[0];
  12640. if( (check_ascii < 48) || (check_ascii > 57) )
  12641. {
  12642. isSuccess = ConfigurationStatus_Rejected;
  12643. }
  12644. else
  12645. {
  12646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12647. isSuccess = ConfigurationStatus_Accepted;
  12648. }
  12649. }
  12650. else
  12651. {
  12652. isSuccess = ConfigurationStatus_Rejected;
  12653. }
  12654. }
  12655. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12656. {
  12657. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12658. {
  12659. strcpy(str, (const char*)value);
  12660. for(int i = 0; str[i]; i++)
  12661. {
  12662. str[i] = tolower(str[i]);
  12663. }
  12664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12665. isSuccess = ConfigurationStatus_Accepted;
  12666. }
  12667. else
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. }
  12672. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12673. {
  12674. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12675. {
  12676. check_ascii = value[0];
  12677. if( (check_ascii < 48) || (check_ascii > 57) )
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. else
  12682. {
  12683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12684. isSuccess = ConfigurationStatus_Accepted;
  12685. }
  12686. }
  12687. else
  12688. {
  12689. isSuccess = ConfigurationStatus_Rejected;
  12690. }
  12691. }
  12692. return isSuccess;
  12693. }
  12694. int TransactionMessageAttemptsGet(void)
  12695. {
  12696. return TransactionMessageAttemptsValue;
  12697. }
  12698. int FirstHeartBeatResponse(void)
  12699. {
  12700. return FirstHeartBeat;
  12701. }
  12702. int TransactionMessageRetryIntervalGet(void)
  12703. {
  12704. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12705. }
  12706. int ReadHttpStatus(int sock)
  12707. {
  12708. //char c;
  12709. char buff[1024]="",*ptr=buff+1;
  12710. int bytes_received, status;
  12711. DEBUG_INFO("Begin Response ..\n");
  12712. while((bytes_received = recv(sock, ptr, 1, 0))){
  12713. if(bytes_received==-1){
  12714. perror("ReadHttpStatus");
  12715. exit(1);
  12716. }
  12717. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12718. ptr++;
  12719. }
  12720. *ptr=0;
  12721. ptr=buff+1;
  12722. sscanf(ptr,"%*s %d ", &status);
  12723. DEBUG_INFO("%s\n",ptr);
  12724. DEBUG_INFO("status=%d\n",status);
  12725. DEBUG_INFO("End Response ..\n");
  12726. return (bytes_received>0)?status:0;
  12727. }
  12728. //the only filed that it parsed is 'Content-Length'
  12729. int ParseHeader(int sock)
  12730. {
  12731. //char c;
  12732. char buff[1024]="",*ptr=buff+4;
  12733. int bytes_received;
  12734. DEBUG_INFO("Begin HEADER ..\n");
  12735. while((bytes_received = recv(sock, ptr, 1, 0))){
  12736. if(bytes_received==-1){
  12737. perror("Parse Header");
  12738. exit(1);
  12739. }
  12740. if(
  12741. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12742. (ptr[-1]=='\r') && (*ptr=='\n' )
  12743. ) break;
  12744. ptr++;
  12745. }
  12746. *ptr=0;
  12747. ptr=buff+4;
  12748. //printf("%s",ptr);
  12749. if(bytes_received){
  12750. ptr=strstr(ptr,"Content-Length:");
  12751. if(ptr){
  12752. sscanf(ptr,"%*s %d",&bytes_received);
  12753. }else
  12754. bytes_received=-1; //unknown size
  12755. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12756. }
  12757. DEBUG_INFO("End HEADER ..\n");
  12758. return bytes_received ;
  12759. }
  12760. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12761. {
  12762. char rmFileCmd[100]={0};
  12763. char FilePath[100]={0};
  12764. char ftpbuf[200];
  12765. int systemresult;
  12766. //DEBUG_INFO("filename=%s\n",filename);
  12767. //DEBUG_INFO("url=%s\n",url);
  12768. sprintf(FilePath,"/mnt/%s",filename);
  12769. if((access(FilePath,F_OK))!=-1)
  12770. {
  12771. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12772. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12773. system(rmFileCmd);
  12774. }
  12775. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12776. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12777. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12778. systemresult = system(ftpbuf);
  12779. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12780. if(systemresult != 0)
  12781. {
  12782. DEBUG_INFO("http DownLoad error!\n");
  12783. return FALSE;
  12784. }
  12785. return TRUE;
  12786. }
  12787. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12788. {
  12789. char rmFileCmd[100]={0};
  12790. char FilePath[100]={0};
  12791. char ftpbuf[200];
  12792. int systemresult;
  12793. //char temp[100];
  12794. sprintf(FilePath,"/mnt/%s",filename);
  12795. if((access(FilePath,F_OK))!=-1)
  12796. {
  12797. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12798. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12799. system(rmFileCmd);
  12800. }
  12801. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12802. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12803. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12804. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12805. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12806. systemresult = system(ftpbuf);
  12807. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12808. if(systemresult != 0)
  12809. {
  12810. printf("wget error!\n");
  12811. return FALSE;
  12812. }
  12813. return TRUE;
  12814. }
  12815. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12816. {
  12817. char rmFileCmd[100]={0};
  12818. char FilePath[100]={0};
  12819. char ftpbuf[200];
  12820. int systemresult;
  12821. //DEBUG_INFO("filename=%s\n",filename);
  12822. //DEBUG_INFO("url=%s\n",url);
  12823. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12824. if((access(FilePath,F_OK))!=-1)
  12825. {
  12826. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12827. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12828. system(rmFileCmd);
  12829. }
  12830. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12831. if(fp == NULL)
  12832. {
  12833. DEBUG_INFO("log is NULL\n");
  12834. return FALSE;
  12835. }
  12836. else
  12837. {
  12838. fprintf(fp, "%s\n", url);
  12839. fprintf(fp, "%s\n", filename);
  12840. fclose(fp);
  12841. }
  12842. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12843. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12844. systemresult = system(ftpbuf);
  12845. DEBUG_INFO("systemresult = %d\n",systemresult);
  12846. if(systemresult != 0)
  12847. {
  12848. DEBUG_INFO("http upload error!\n");
  12849. return FALSE;
  12850. }
  12851. return TRUE;
  12852. }
  12853. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12854. {
  12855. struct hostent* server;
  12856. char *IPbuffer;
  12857. char ftpbuf[200];
  12858. int systemresult;
  12859. // To retrieve host information
  12860. server = gethostbyname(location);
  12861. // To convert an Internet network
  12862. // address into ASCII string
  12863. IPbuffer = inet_ntoa(*((struct in_addr*)
  12864. server->h_addr_list[0]));
  12865. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12866. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12867. /* format : ftpput -u username -p passwd IP target source*/
  12868. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12869. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12870. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12871. systemresult = system(ftpbuf);
  12872. DEBUG_INFO("systemresult=%d\n",systemresult);
  12873. if(systemresult != 0)
  12874. {
  12875. DEBUG_INFO("ftpput error!\n");
  12876. return FALSE;
  12877. }
  12878. return TRUE;
  12879. }
  12880. /**
  12881. * Place the contents of the specified file into a memory buffer
  12882. *
  12883. * @param[in] filename The path and name of the file to read
  12884. * @param[out] filebuffer A pointer to the contents in memory
  12885. * @return status 0 success, 1 on failure
  12886. */
  12887. int get_file_contents(const char* filename, char** outbuffer) {
  12888. FILE* file = NULL;
  12889. long filesize;
  12890. const int blocksize = 1;
  12891. size_t readsize;
  12892. char* filebuffer;
  12893. // Open the file
  12894. file = fopen(filename, "r");
  12895. if (NULL == file)
  12896. {
  12897. printf("'%s' not opened\n", filename);
  12898. exit(EXIT_FAILURE);
  12899. }
  12900. // Determine the file size
  12901. fseek(file, 0, SEEK_END);
  12902. filesize = ftell(file);
  12903. rewind (file);
  12904. // Allocate memory for the file contents
  12905. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12906. *outbuffer = filebuffer;
  12907. if (filebuffer == NULL)
  12908. {
  12909. fputs ("malloc out-of-memory", stderr);
  12910. exit(EXIT_FAILURE);
  12911. }
  12912. // Read in the file
  12913. readsize = fread(filebuffer, blocksize, filesize, file);
  12914. if (readsize != filesize)
  12915. {
  12916. fputs ("didn't read file completely",stderr);
  12917. exit(EXIT_FAILURE);
  12918. }
  12919. // Clean exit
  12920. fclose(file);
  12921. return EXIT_SUCCESS;
  12922. }
  12923. static int selectSqlCount = 0;
  12924. static int callback(void *data, int argc, char **argv, char **azColName){
  12925. int i;
  12926. //printf("%s: ", (const char*)data);
  12927. selectSqlCount = argc;
  12928. for(i = 0; i<argc; i++){
  12929. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12930. }
  12931. //printf("\n");
  12932. return 0;
  12933. }
  12934. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12935. //int i;
  12936. //printf("%s:\n", (const char*)data);
  12937. localversion = argv[5] ? atoi(argv[5]) : 0;
  12938. //printf("localversion=%d\n", localversion);
  12939. return 0;
  12940. }
  12941. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12942. //int i;
  12943. //printf("%s:\n", (const char*)data);
  12944. //idTag
  12945. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12946. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12947. //parentIdTag
  12948. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12949. //expir_date
  12950. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12951. //status
  12952. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12953. //version
  12954. idTagQuery.listVersionInt = atoi(argv[5]);
  12955. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12956. return 0;
  12957. }
  12958. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12959. {
  12960. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12961. // printf("localversion=%d\n", localversion);
  12962. return 0;
  12963. }
  12964. //=========================================
  12965. // Sqlite3 related function
  12966. //=========================================
  12967. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12968. {
  12969. for (int i = 0; i < n_columns; i++)
  12970. {
  12971. DEBUG_INFO("%s/t", col_values[i]);
  12972. }
  12973. DEBUG_INFO("/n");
  12974. return 0;
  12975. }
  12976. void OCPP_getListVerion()
  12977. {
  12978. int rc = 0;
  12979. // const char* data = "Callback function called";
  12980. char sql[100];
  12981. char zErrMsg[100];
  12982. memset(sql, 0, 100);
  12983. memset(zErrMsg, 0, 100);
  12984. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12985. /* Execute SQL statement */
  12986. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12987. if( rc != SQLITE_OK )
  12988. {
  12989. DEBUG_INFO("SQL error: %s", zErrMsg);
  12990. }
  12991. }
  12992. void OCPP_getIdTag(char idTag[])
  12993. {
  12994. int rc = 0;
  12995. // const char* data = "Callback function called";
  12996. char sql[100];
  12997. char zErrMsg[100];
  12998. memset(sql, 0, 100);
  12999. memset(zErrMsg, 0, 100);
  13000. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13001. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13002. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13003. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13004. /* Execute SQL statement */
  13005. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13006. if( rc != SQLITE_OK )
  13007. {
  13008. DEBUG_INFO("SQL error: %s", zErrMsg);
  13009. }
  13010. //return ver;
  13011. }
  13012. void OCPP_get_TableAuthlocalAllData(void)
  13013. {
  13014. int rc = 0;
  13015. char sql[100];
  13016. char zErrMsg[100];
  13017. memset(sql, 0, 100);
  13018. memset(zErrMsg, 0, 100);
  13019. sprintf(sql,"select * from ocpp_auth_local ");
  13020. /* Execute SQL statement */
  13021. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13022. if( rc != SQLITE_OK )
  13023. {
  13024. DEBUG_INFO("SQL error: %s", zErrMsg);
  13025. }
  13026. //return ver;
  13027. }
  13028. int OCPP_cleanLocalList()
  13029. {
  13030. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13031. char *errMsg = 0;
  13032. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13033. if (SQLITE_OK != rc)
  13034. {
  13035. DEBUG_INFO("%s\n",errMsg);
  13036. return FALSE;
  13037. }
  13038. return TRUE;
  13039. }
  13040. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13041. {
  13042. int isSuccess = FALSE;
  13043. int ret = 0;
  13044. //const char* data = "Callback function called";
  13045. char sql[300];
  13046. char zErrMsg[200];
  13047. memset(sql, 0, 300);
  13048. memset(zErrMsg, 0, 200);
  13049. 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);
  13050. //* Execute SQL statement */
  13051. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13052. if( ret != SQLITE_OK )
  13053. {
  13054. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13055. return isSuccess;
  13056. }
  13057. memset(sql, 0, 300);
  13058. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13059. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13060. if( ret != SQLITE_OK )
  13061. {
  13062. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13063. return isSuccess;
  13064. }
  13065. isSuccess = TRUE;
  13066. return isSuccess;
  13067. }
  13068. void OCPP_deleteIdTag(char idTag[])
  13069. {
  13070. //int ver = 0;
  13071. //int isSuccess = FALSE;
  13072. int rc = 0;
  13073. char sql[100];
  13074. char zErrMsg[100];
  13075. memset(sql, 0, 100);
  13076. memset(zErrMsg, 0, 100);
  13077. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13078. //* Execute SQL statement */
  13079. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13080. if( rc != SQLITE_OK )
  13081. {
  13082. DEBUG_INFO("SQL error: %s", zErrMsg);
  13083. }
  13084. }
  13085. int GetOcppServerURL()
  13086. {
  13087. int result = FALSE;
  13088. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13089. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13090. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13091. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13092. {
  13093. #if 1
  13094. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13095. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13096. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13097. #endif
  13098. result = TRUE;
  13099. goto End;
  13100. }
  13101. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13102. {
  13103. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13104. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13105. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13106. result = TRUE;
  13107. goto End;
  13108. }
  13109. else
  13110. {
  13111. strcpy(OcppHost,"");
  13112. }
  13113. End:
  13114. return result;
  13115. }
  13116. int GetOcppPath()
  13117. {
  13118. int result = FALSE;
  13119. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13120. {
  13121. if(OcppTempPath == NULL)
  13122. {
  13123. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13124. }
  13125. else
  13126. {
  13127. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13128. }
  13129. result = TRUE;
  13130. goto End;
  13131. }
  13132. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13133. {
  13134. if(OcppTempPath == NULL)
  13135. {
  13136. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13137. }
  13138. else
  13139. {
  13140. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13141. }
  13142. result = TRUE;
  13143. goto End;
  13144. }
  13145. else
  13146. {
  13147. strcpy(OcppPath,"");
  13148. }
  13149. End:
  13150. return result;
  13151. }
  13152. int GetOcppPort()
  13153. {
  13154. return OcppPort;
  13155. }
  13156. int GetOcppConnStatus(void)
  13157. {
  13158. return ShmOCPP16Data->OcppConnStatus;
  13159. }
  13160. void SetOcppConnStatus(uint8_t status)
  13161. {
  13162. ShmOCPP16Data->OcppConnStatus = status;
  13163. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13164. }
  13165. int GetHeartBeatWithNOResponse(void)
  13166. {
  13167. return HeartBeatWithNOResponse;
  13168. }
  13169. void SetHeartBeatWithNOResponse(void)
  13170. {
  13171. HeartBeatWithNOResponse = 0;
  13172. }
  13173. void GetStartTransactionIdTag(int gun_index)
  13174. {
  13175. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13176. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13177. }
  13178. int GetTransactionId(int gunindex, unsigned char idTag[])
  13179. {
  13180. char ch;
  13181. FILE *fptr1;
  13182. int temptransactionId;
  13183. char str[100]={0};
  13184. temptransactionId = 0;
  13185. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13186. {
  13187. DEBUG_INFO("IdTag is empty.\n");
  13188. return temptransactionId;
  13189. }
  13190. /*------ Read the file ----------------*/
  13191. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13192. if (!fptr1)
  13193. {
  13194. DEBUG_INFO("QueueTransactionId file open error.\n");
  13195. //printf(" File not found or unable to open the input file!!\n");
  13196. return temptransactionId;
  13197. }
  13198. ch=fgetc(fptr1);
  13199. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13200. rewind(fptr1);
  13201. if(ch!=EOF)
  13202. {
  13203. // printf("%c",ch);
  13204. while (fgets(str, 100, fptr1) != NULL)
  13205. {
  13206. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13207. if(str[0]=='\0')
  13208. {
  13209. break;
  13210. }
  13211. char *revbuf[8] = {0}; //存放分割後的子字串
  13212. int num = 0;//分割後子字串的個數
  13213. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13214. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13215. {
  13216. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13217. {
  13218. temptransactionId = atoi(revbuf[2]);
  13219. break;
  13220. }
  13221. }
  13222. }
  13223. }
  13224. fclose(fptr1);
  13225. /*------- End of reading ---------------*/
  13226. return temptransactionId;
  13227. }
  13228. void SetTransactionIdZero(int transactionId)
  13229. {
  13230. char ch;
  13231. FILE *fptr1, *fptr2;
  13232. int temptransactionId = 0;
  13233. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13234. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13235. if (!fptr1)
  13236. {
  13237. //printf(" File not found or unable to open the input file!!\n");
  13238. return ;
  13239. }
  13240. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13241. if (!fptr2)
  13242. {
  13243. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13244. fclose(fptr1);
  13245. return ;
  13246. }
  13247. ch=fgetc(fptr1);
  13248. rewind(fptr1);
  13249. if(ch!=EOF)
  13250. {
  13251. // copy all contents to the temporary file except the specific line
  13252. while (fgets(str, 100, fptr1) != NULL)
  13253. {
  13254. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13255. if(str[0]=='\0')
  13256. {
  13257. break;
  13258. }
  13259. char *revbuf[8] = {0};
  13260. int num = 0;
  13261. strcpy(strtemp, str);
  13262. splitstring(str,",",revbuf,&num);
  13263. if(revbuf[2][0] != '\0')
  13264. {
  13265. temptransactionId = atoi(revbuf[2]);
  13266. if(transactionId != temptransactionId)
  13267. {
  13268. fprintf(fptr2, "%s\n", strtemp);
  13269. }
  13270. }
  13271. }
  13272. }
  13273. fclose(fptr1);
  13274. fclose(fptr2);
  13275. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13276. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13277. /*------ Read the file ----------------*/
  13278. }
  13279. int InternetDisconnect(void)
  13280. {
  13281. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13282. }
  13283. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13284. void storeTempStopTransaction(int gun_index)
  13285. {
  13286. char guid[37]={0};
  13287. int tempIndex = 0;
  13288. DEBUG_INFO("storeTempStopTransaction...\n");
  13289. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13290. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13291. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13292. if(gunType[gun_index] == 'J')
  13293. {
  13294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13295. {
  13296. tempIndex = ((gun_index==2) ? 1: 0);
  13297. }
  13298. else
  13299. {
  13300. tempIndex = gun_index;
  13301. }
  13302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13303. {
  13304. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13305. {
  13306. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13307. }
  13308. }// END OF CHAdeMO_QUANTITY
  13309. }
  13310. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13311. {
  13312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13313. {
  13314. tempIndex = ((gun_index==2) ? 1: 0);
  13315. }
  13316. else
  13317. {
  13318. tempIndex = gun_index;
  13319. }
  13320. for (int index = 0; index < CCS_QUANTITY; index++)
  13321. {
  13322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13323. {
  13324. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13325. }
  13326. }// END OF CCS_QUANTITY
  13327. }
  13328. else if(gunType[gun_index] == 'G')
  13329. {
  13330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13331. {
  13332. tempIndex = ((gun_index==2) ? 1: 0);
  13333. }
  13334. else
  13335. {
  13336. tempIndex = gun_index;
  13337. }
  13338. for (int index = 0; index < GB_QUANTITY; index++)
  13339. {
  13340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13341. {
  13342. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13343. }
  13344. }// END OF GB_QUANTITY
  13345. }
  13346. else
  13347. {
  13348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13349. {
  13350. tempIndex = 2;
  13351. }
  13352. else
  13353. {
  13354. tempIndex = gun_index;
  13355. }
  13356. for (int index = 0; index < AC_QUANTITY; index++)
  13357. {
  13358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13359. {
  13360. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13361. }
  13362. }// END OF AC_QUANTITY
  13363. }
  13364. //Stop Transaction Time
  13365. struct timeval tmnow;
  13366. struct tm *tm;
  13367. char buf[28];//, usec_buf[6];
  13368. gettimeofday(&tmnow, NULL);
  13369. time_t t;
  13370. t = time(NULL);
  13371. /*UTC time and date*/
  13372. tm = gmtime(&t);
  13373. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13375. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13377. random_uuid(guid);
  13378. /***********************************transactionData******************************************************/
  13379. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13381. //=================================
  13382. //1. Transaction_Begin
  13383. //=================================
  13384. //============================== Energy.Active.Import.Interval ===========================================
  13385. //idx_sample=0;
  13386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13389. 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*/]);
  13390. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13391. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13392. {
  13393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13394. }
  13395. else
  13396. {
  13397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13398. }
  13399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13401. //=================================
  13402. //2. Transaction_End
  13403. //=================================
  13404. //2.1====================================== Current.Import L1 ==============================================
  13405. //idx_sample=1;
  13406. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13407. if(gunType[gun_index] == 'J')
  13408. {
  13409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13410. {
  13411. tempIndex = ((gun_index==2) ? 1: 0);
  13412. }
  13413. else
  13414. {
  13415. tempIndex = gun_index;
  13416. }
  13417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13418. {
  13419. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13420. {
  13421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13422. }
  13423. }// End of for CHAdeMO_QUANTITY
  13424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13425. }
  13426. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13427. {
  13428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13429. {
  13430. tempIndex = ((gun_index==2) ? 1: 0);
  13431. }
  13432. else
  13433. {
  13434. tempIndex = gun_index;
  13435. }
  13436. for (int index = 0; index < CCS_QUANTITY; index++)
  13437. {
  13438. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13439. {
  13440. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13441. }
  13442. }// End of for CCS_QUANTITY
  13443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13444. }
  13445. else if(gunType[gun_index] == 'G')
  13446. {
  13447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13448. {
  13449. tempIndex = ((gun_index==2) ? 1: 0);
  13450. }
  13451. else
  13452. {
  13453. tempIndex = gun_index;
  13454. }
  13455. for (int index = 0; index < GB_QUANTITY; index++)
  13456. {
  13457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13458. {
  13459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13460. }
  13461. }// End of for GB_QUANTITY
  13462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13463. }
  13464. else
  13465. {
  13466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13467. {
  13468. tempIndex = 2;
  13469. }
  13470. else
  13471. {
  13472. tempIndex = gun_index;
  13473. }
  13474. for (int index = 0; index < AC_QUANTITY; index++)
  13475. {
  13476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13477. {
  13478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13479. }
  13480. }// End of for AC_QUANTITY
  13481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13482. }
  13483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13486. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13489. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13490. //idx_sample=2;
  13491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13492. if(gunType[gun_index] == 'J')
  13493. {
  13494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13495. {
  13496. tempIndex = ((gun_index==2) ? 1: 0);
  13497. }
  13498. else
  13499. {
  13500. tempIndex = gun_index;
  13501. }
  13502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13503. {
  13504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13505. {
  13506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13507. }
  13508. }// END OF CHAdeMO_QUANTITY
  13509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13510. }
  13511. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13512. {
  13513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13514. {
  13515. tempIndex = ((gun_index==2) ? 1: 0);
  13516. }
  13517. else
  13518. {
  13519. tempIndex = gun_index;
  13520. }
  13521. for (int index = 0; index < CCS_QUANTITY; index++)
  13522. {
  13523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13524. {
  13525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13526. }
  13527. }// END OF CCS_QUANTITY
  13528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13529. }
  13530. else if(gunType[gun_index] == 'G')
  13531. {
  13532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13533. {
  13534. tempIndex = ((gun_index==2) ? 1: 0);
  13535. }
  13536. else
  13537. {
  13538. tempIndex = gun_index;
  13539. }
  13540. for (int index = 0; index < GB_QUANTITY; index++)
  13541. {
  13542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13543. {
  13544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13545. }
  13546. }// END OF GB_QUANTITY
  13547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13548. }
  13549. else
  13550. {
  13551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13552. {
  13553. tempIndex = 2;
  13554. }
  13555. else
  13556. {
  13557. tempIndex = gun_index;
  13558. }
  13559. for (int index = 0; index < AC_QUANTITY; index++)
  13560. {
  13561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13562. {
  13563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13564. }
  13565. }// END OF AC_QUANTITY
  13566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13567. }
  13568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13571. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13574. //2.3====================================== Power.Active.Export =========================================
  13575. //idx_sample=3;
  13576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13577. if(gunType[gun_index] == 'J')
  13578. {
  13579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13580. {
  13581. tempIndex = ((gun_index==2) ? 1: 0);
  13582. }
  13583. else
  13584. {
  13585. tempIndex = gun_index;
  13586. }
  13587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13588. {
  13589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13590. {
  13591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13592. }
  13593. } // End for CHAdeMO_QUANTITY
  13594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13595. }
  13596. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13597. {
  13598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13599. {
  13600. tempIndex = ((gun_index==2) ? 1: 0);
  13601. }
  13602. else
  13603. {
  13604. tempIndex = gun_index;
  13605. }
  13606. for (int index = 0; index < CCS_QUANTITY; index++)
  13607. {
  13608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13609. {
  13610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13611. }
  13612. } // END for CCS_QUANTITY
  13613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13614. }
  13615. else if(gunType[gun_index] == 'G')
  13616. {
  13617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13618. {
  13619. tempIndex = ((gun_index==2) ? 1: 0);
  13620. }
  13621. else
  13622. {
  13623. tempIndex = gun_index;
  13624. }
  13625. for (int index = 0; index < GB_QUANTITY; index++)
  13626. {
  13627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13628. {
  13629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13630. }
  13631. }// END for GB_QUANTITY
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13633. }
  13634. else
  13635. {
  13636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13637. {
  13638. tempIndex = 2;
  13639. }
  13640. else
  13641. {
  13642. tempIndex = gun_index;
  13643. }
  13644. for (int index = 0; index < AC_QUANTITY; index++)
  13645. {
  13646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13647. {
  13648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13649. }
  13650. } // END for AC_QUANTITY
  13651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13652. }
  13653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13656. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13659. //2.4====================================== Voltage L1 ====================================================
  13660. //idx_sample=4;
  13661. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13662. if(gunType[gun_index] == 'J')
  13663. {
  13664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13665. {
  13666. tempIndex = ((gun_index==2) ? 1: 0);
  13667. }
  13668. else
  13669. {
  13670. tempIndex = gun_index;
  13671. }
  13672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13673. {
  13674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13675. {
  13676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13677. }
  13678. } // END OF FOR CHAdeMO_QUANTITY
  13679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13680. }
  13681. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13682. {
  13683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13684. {
  13685. tempIndex = ((gun_index==2) ? 1: 0);
  13686. }
  13687. else
  13688. {
  13689. tempIndex = gun_index;
  13690. }
  13691. for (int index = 0; index < CCS_QUANTITY; index++)
  13692. {
  13693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13694. {
  13695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13696. }
  13697. } // END OF FOR CCS_QUANTITY
  13698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13699. }
  13700. else if(gunType[gun_index] == 'G')
  13701. {
  13702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13703. {
  13704. tempIndex = ((gun_index==2) ? 1: 0);
  13705. }
  13706. else
  13707. {
  13708. tempIndex = gun_index;
  13709. }
  13710. for (int index = 0; index < GB_QUANTITY; index++)
  13711. {
  13712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13713. {
  13714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13715. }
  13716. } // END OF FOR GB_QUANTITY
  13717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13718. }
  13719. else
  13720. {
  13721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13722. {
  13723. tempIndex = 2;
  13724. }
  13725. else
  13726. {
  13727. tempIndex = gun_index;
  13728. }
  13729. for (int index = 0; index < AC_QUANTITY; index++)
  13730. {
  13731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13732. {
  13733. 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
  13734. }
  13735. } // END OF FOR AC_QUANTITY
  13736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13737. }
  13738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13741. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13744. //2.5============================================== SoC =========================================================
  13745. //idx_sample=5;
  13746. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13747. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13748. {
  13749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13750. {
  13751. tempIndex = ((gun_index==2) ? 1: 0);
  13752. }
  13753. else
  13754. {
  13755. tempIndex = gun_index;
  13756. }
  13757. if(gunType[gun_index] == 'J')
  13758. {
  13759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13760. {
  13761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13762. {
  13763. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13764. }
  13765. }
  13766. }
  13767. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13768. {
  13769. for (int index = 0; index < CCS_QUANTITY; index++)
  13770. {
  13771. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13772. {
  13773. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13774. }
  13775. }
  13776. }
  13777. else if(gunType[gun_index] == 'G')
  13778. {
  13779. for (int index = 0; index < GB_QUANTITY; index++)
  13780. {
  13781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13782. {
  13783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13784. }
  13785. }
  13786. }
  13787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13793. } // END FOR DC CASE
  13794. //2.6====================================== Current.Import L2 ==============================================
  13795. // idx_sample=6;
  13796. // AC 3 phase L2 current
  13797. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13798. {
  13799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13800. {
  13801. tempIndex = 2;
  13802. }
  13803. else
  13804. {
  13805. tempIndex = gun_index;
  13806. }
  13807. for (int index = 0; index < AC_QUANTITY; index++)
  13808. {
  13809. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13810. {
  13811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13812. }
  13813. }// End of for AC_QUANTITY
  13814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13815. }
  13816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13821. //2.7====================================== Current.Import L3 ==============================================
  13822. // idx_sample=7;
  13823. // AC 3 phase L3 current
  13824. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13825. {
  13826. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13827. {
  13828. tempIndex = 2;
  13829. }
  13830. else
  13831. {
  13832. tempIndex = gun_index;
  13833. }
  13834. for (int index = 0; index < AC_QUANTITY; index++)
  13835. {
  13836. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13837. {
  13838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13839. }
  13840. }// End of for AC_QUANTITY
  13841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13842. }
  13843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13848. //2.9====================================== Voltage L2 ====================================================
  13849. //idx_sample=8;
  13850. // AC 3 phase L2 volatge
  13851. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13852. {
  13853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13854. {
  13855. tempIndex = 2;
  13856. }
  13857. else
  13858. {
  13859. tempIndex = gun_index;
  13860. }
  13861. for (int index = 0; index < AC_QUANTITY; index++)
  13862. {
  13863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13864. {
  13865. 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
  13866. }
  13867. } // END OF FOR AC_QUANTITY
  13868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13869. }
  13870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13875. //2.10====================================== Voltage L3 ====================================================
  13876. //idx_sample=9;
  13877. // AC 3 phase L3 volatge
  13878. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13879. {
  13880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13881. {
  13882. tempIndex = 2;
  13883. }
  13884. else
  13885. {
  13886. tempIndex = gun_index;
  13887. }
  13888. for (int index = 0; index < AC_QUANTITY; index++)
  13889. {
  13890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13891. {
  13892. 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
  13893. }
  13894. } // END OF FOR AC_QUANTITY
  13895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13896. }
  13897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13902. //======================================== Message create ==============================================
  13903. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13904. {
  13905. 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\"}]}]}]"
  13906. ,gun_index+1
  13907. ,MESSAGE_TYPE_CALL
  13908. ,guid
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13913. ,"PowerLoss"
  13914. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13957. );
  13958. }
  13959. else
  13960. {
  13961. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13962. {
  13963. 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\"}]}]}]"
  13964. ,gun_index+1
  13965. ,MESSAGE_TYPE_CALL
  13966. ,guid
  13967. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13968. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13969. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13971. ,"PowerLoss"
  13972. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14008. );
  14009. }
  14010. else
  14011. {
  14012. 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\"}]}]}]"
  14013. ,gun_index+1
  14014. ,MESSAGE_TYPE_CALL
  14015. ,guid
  14016. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14017. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14018. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14020. ,"PowerLoss"
  14021. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14046. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14047. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14048. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14049. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14050. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14085. );
  14086. }
  14087. }
  14088. // Check File "TempStopTransaction" Exist
  14089. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14090. {
  14091. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14092. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14093. }
  14094. else
  14095. {
  14096. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14097. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14098. if(log == NULL)
  14099. {
  14100. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14101. return ;
  14102. }
  14103. else
  14104. {
  14105. fclose(log);
  14106. }
  14107. }
  14108. //Add TempStopTransaction | Update TempStopTransaction
  14109. // open file for writing
  14110. FILE *outfile;
  14111. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14112. //DEBUG_INFO("data = %s\n", queuedata);
  14113. fputs(queuedata, outfile);
  14114. fputs("\n", outfile);
  14115. fclose (outfile);
  14116. }
  14117. void checkTempStopTransaction(int gun_index)
  14118. {
  14119. FILE *fptr1;
  14120. char ch;
  14121. char str[QUEUE_MESSAGE_LENGTH]={0};
  14122. char guid[37]={0};
  14123. char tempdata[65]={0};
  14124. char connectorStr[2]={0};
  14125. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14126. //TempStopTransaction格式: 槍號,StopTransaction封包
  14127. if (!fptr1)
  14128. {
  14129. //printf(" File not found or unable to open the input file!!\n");
  14130. return ;
  14131. }
  14132. ch=fgetc(fptr1);
  14133. //printf(" Now the content of the file %s is : \n",fname);
  14134. rewind(fptr1);
  14135. if(ch!=EOF)
  14136. {
  14137. // copy all contents to the temporary file except the specific line
  14138. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14139. {
  14140. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14141. if(str[0]=='\0')
  14142. {
  14143. break;
  14144. }
  14145. //TempStopTransaction格式: 槍號,StopTransaction封包
  14146. strncpy(connectorStr, str, 1);
  14147. if(atoi(connectorStr) != (gun_index+1))
  14148. {
  14149. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14150. return ;
  14151. }
  14152. //random_uuid(guid);
  14153. strncpy(guid, str+6, 36); //copy guid
  14154. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14155. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14156. {
  14157. DEBUG_INFO("StopTransaction mapitem pass\n");
  14158. }
  14159. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14160. memset(str,0,ARRAY_SIZE(str));
  14161. }
  14162. }
  14163. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14164. fclose(fptr1);
  14165. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14166. }
  14167. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14168. {
  14169. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14170. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14171. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14172. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14173. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14174. }
  14175. int GetWebSocketPingInterval(void)
  14176. {
  14177. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14178. }
  14179. int GetServerSign(void)
  14180. {
  14181. return server_sign;
  14182. }
  14183. void SetServerSign(int value)
  14184. {
  14185. server_sign = value;
  14186. }
  14187. int GetBootNotificationInterval(void)
  14188. {
  14189. return BootNotificationInterval;
  14190. }
  14191. int GetInternetConn(void)
  14192. {
  14193. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14194. }
  14195. void InitialSystemValue(void)
  14196. {
  14197. int connectorIndex = 0;
  14198. //int valueASCII = 0;
  14199. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14200. gunTotalNumber=0;
  14201. SystemInitial = 0;
  14202. localversion=0;
  14203. BootNotificationInterval = 0;
  14204. authorizeRetryTimes = 0;
  14205. GunStatusInterval = 10;
  14206. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14207. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14208. //Hear Beat
  14209. HeartBeatWithNOResponse = 0;
  14210. HeartBeatCountPerHour = 0;
  14211. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14212. FirstHeartBeat = 0;
  14213. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14214. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14215. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14216. memset(statusModeChage, 0, sizeof(statusModeChage));
  14217. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  14218. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  14219. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  14220. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  14221. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  14222. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  14223. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  14224. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  14225. memset(gunType, 0, sizeof(gunType));
  14226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14227. {
  14228. //check connector / socket type (index: 8, 9, 10)
  14229. for(int index=7; index <10 ; index++)
  14230. {
  14231. if(index != 8)
  14232. {
  14233. // DC Connector
  14234. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14235. {
  14236. SystemInitial = SystemInitial + 1;
  14237. gunTotalNumber = gunTotalNumber + 1;
  14238. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14239. connectorIndex = connectorIndex + 1;
  14240. }
  14241. }
  14242. else
  14243. {
  14244. // AC Connector
  14245. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14246. {
  14247. SystemInitial = SystemInitial + 1;
  14248. gunTotalNumber = gunTotalNumber + 1;
  14249. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14250. connectorIndex = connectorIndex + 1;
  14251. }
  14252. }
  14253. }
  14254. //DEBUG_INFO("DC ...\n");
  14255. }
  14256. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14257. {
  14258. //check connector / socket type (index: 8, 9, 10)
  14259. for(int index=7; index <10 ; index++)
  14260. {
  14261. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14262. {
  14263. SystemInitial = SystemInitial + 1;
  14264. gunTotalNumber = gunTotalNumber + 1;
  14265. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14266. connectorIndex = connectorIndex + 1;
  14267. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14268. }
  14269. }
  14270. }
  14271. //Status && ConnectorPlugIn Setting
  14272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14273. {
  14274. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14275. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14276. }
  14277. for (int index = 0; index < CCS_QUANTITY; index++)
  14278. {
  14279. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14280. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14281. }
  14282. for (int index = 0; index < GB_QUANTITY; index++)
  14283. {
  14284. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14285. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14286. }
  14287. for (int index = 0; index < AC_QUANTITY; index++)
  14288. {
  14289. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14290. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14291. }
  14292. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14293. {
  14294. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14295. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14296. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14297. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14298. }
  14299. // Charger PRE_SYS_MODE
  14300. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  14301. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14302. clientTime.Heartbeat=time((time_t*)NULL);
  14303. sleep(1);
  14304. }
  14305. void LWS_Send(char * str)
  14306. {
  14307. //=====================================================
  14308. // Check InternetConn 0: disconnected, 1: connected
  14309. //====================================================
  14310. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14311. {
  14312. DEBUG_INFO("offline now !!!\n");
  14313. return;
  14314. }
  14315. pthread_mutex_lock(&lock_send);
  14316. memset(SendBuffer, 0, SendBufLen);
  14317. sprintf((char *)SendBuffer, "%s", str);
  14318. pthread_mutex_unlock(&lock_send);
  14319. lws_callback_on_writable(wsi_client);
  14320. lws_service(context, 0);
  14321. //sleep(1);
  14322. }