MessageHandler.c 668 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484
  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 uint8_t 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. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. //int isUpdateRequest = FALSE;
  59. static int HeartBeatWaitTime = 10;
  60. static int FirstHeartBeat = 0;
  61. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  62. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  63. static char CurrentChargingProfileScheduleStr[30] = {0};
  64. //========================================
  65. // OCPP status/previous related variables
  66. //========================================
  67. static int GunStatusInterval = 10;
  68. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  69. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  70. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  71. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  72. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  73. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  74. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  75. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  76. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  77. static int TransactionMessageAttemptsValue = 0;
  78. static int TransactionMessageRetryIntervalValue = 0;
  79. static int TempMeterValueInterval = 0;
  80. static struct OCPPAuthLocalElemet
  81. {
  82. int listVersionInt;
  83. char idTagstr[20];
  84. char parentIdTag[20];
  85. char expiryDate[30];
  86. char idTagstatus[16];
  87. }idTagQuery;
  88. //=============================================
  89. // OCPP HeartBeat Response Not Receive Counts
  90. //============================================
  91. static int HeartBeatWithNOResponse = 0;
  92. static int HeartBeatCountPerHour = 0;
  93. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  94. extern int GetTransactionQueueNum(void);
  95. extern struct Charger_Info Charger;
  96. extern sqlite3 *db;
  97. int TransactionMessageAttemptsGet(void);
  98. int TransactionMessageRetryIntervalGet(void);
  99. int GetOcppConnStatus(void);
  100. void SetOcppConnStatus(uint8_t status);
  101. int setKeyValue(char *key, char *value);
  102. void OCPP_get_TableAuthlocalAllData(void);
  103. void processUnkownKey(void);
  104. struct StructOCPPMeterValue
  105. {
  106. unsigned char TimeStamp[28];
  107. struct StructSampledValue SampledValue[10];
  108. };
  109. struct ClientTime
  110. {
  111. unsigned int Heartbeat;
  112. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  113. unsigned int StartTransaction;
  114. unsigned int StopTransaction;
  115. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  116. }clientTime;
  117. typedef union
  118. {
  119. //Operations Initiated by Central System
  120. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  121. struct
  122. {
  123. //CsMsgValue[0]
  124. unsigned char StatusNotificationReq :1; //bit 0,
  125. unsigned char StatusNotificationConf :1; //bit 0,
  126. unsigned char :6; //bit 2~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. 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) &&
  422. (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))
  423. {
  424. tmStart.tm_year -= 1900;
  425. tmStart.tm_mon -= 1;
  426. tbStart.time = mktime(&tmStart);
  427. tbStart.millitm = 0;
  428. tmStop.tm_year -= 1900;
  429. tmStop.tm_mon -= 1;
  430. tbStop.time = mktime(&tmStop);
  431. tbStop.millitm = 0;
  432. result = DiffTimebSec(tbStart, tbStop);
  433. }
  434. else
  435. {
  436. DEBUG_WARN("Start or stop date parsing error.\r\n");
  437. }
  438. return result;
  439. }
  440. int getStartSinceToday(uint8_t *stop)
  441. {
  442. int result = -1;
  443. time_t t;
  444. struct tm *tmStartToday;
  445. struct timeb tbStartToday;
  446. struct tm tmStop;
  447. struct timeb tbStop;
  448. 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))
  449. {
  450. t=time(NULL);
  451. tmStartToday=localtime(&t);
  452. tmStartToday->tm_hour = 0;
  453. tmStartToday->tm_min = 0;
  454. tmStartToday->tm_sec = 0;
  455. tbStartToday.time = mktime(tmStartToday);
  456. tmStop.tm_year -= 1900;
  457. tmStop.tm_mon -= 1;
  458. tbStop.time = mktime(&tmStop);
  459. tbStop.millitm = 0;
  460. result = DiffTimebSec(tbStartToday, tbStop);
  461. }
  462. return result;
  463. }
  464. int getStartSinceWeek(uint8_t *stop)
  465. {
  466. int result = -1;
  467. time_t t;
  468. struct tm *tmStartWeek;
  469. struct timeb tbStartWeek;
  470. struct tm tmStop;
  471. struct timeb tbStop;
  472. 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))
  473. {
  474. t=time(NULL);
  475. tmStartWeek=localtime(&t);
  476. t-=86400*tmStartWeek->tm_wday;
  477. tmStartWeek=localtime(&t);
  478. tmStartWeek->tm_hour = 0;
  479. tmStartWeek->tm_min = 0;
  480. tmStartWeek->tm_sec = 0;
  481. tbStartWeek.time = mktime(tmStartWeek);
  482. tmStop.tm_year -= 1900;
  483. tmStop.tm_mon -= 1;
  484. tbStop.time = mktime(&tmStop);
  485. tbStop.millitm = 0;
  486. result = DiffTimebSec(tbStartWeek, tbStop);
  487. }
  488. return result;
  489. }
  490. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  491. {
  492. FILE *fp;
  493. char profileFileName[128];
  494. char *line = NULL;
  495. size_t len = 0;
  496. time_t CurrentTime;
  497. struct tm *tmComposite;
  498. struct StructChargingProfile maxProfile;
  499. struct StructChargingProfile defaultTxProfile;
  500. struct StructChargingProfile txProfile;
  501. struct StructChargingSchedulePeriod tmpPeriod;
  502. uint8_t limitMax=0;
  503. uint8_t limitDef=0;
  504. uint8_t limitTx=0;
  505. int compositePeriodIdx = 0;
  506. CurrentTime = time(NULL);
  507. tmComposite=localtime(&CurrentTime);
  508. 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);
  509. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  510. compositeProfile->ChargingSchedule.Duration = durationReq;
  511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  512. {
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  516. }
  517. compositeProfile->ChargingProfileId = 0;
  518. compositeProfile->StackLevel = 99 ;
  519. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  520. maxProfile.ChargingProfileId = -1;
  521. defaultTxProfile.ChargingProfileId = -1;
  522. txProfile.ChargingProfileId = -1;
  523. system("yes|rm /tmp/*.json");
  524. system("cp /Storage/OCPP/*.json /tmp");
  525. /*
  526. * Search valid charging profile
  527. */
  528. //DEBUG_INFO("====================================\n");
  529. // Search max profile
  530. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  531. if((access(profileFileName, F_OK))!=-1)
  532. {
  533. fp = fopen(profileFileName, "r");
  534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  535. {
  536. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  538. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  539. }
  540. maxProfile.ChargingProfileId = -1;
  541. maxProfile.StackLevel = -1;
  542. while(getline(&line, &len, fp) != -1)
  543. {
  544. json_object *obj = NULL;
  545. obj = json_tokener_parse(line);
  546. if(is_error(obj))
  547. {
  548. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  549. }
  550. else
  551. {
  552. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  553. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  554. )
  555. {
  556. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  557. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  558. )
  559. {
  560. struct tm tmFrom, tmTo;
  561. struct timeb tbFrom, tbTo;
  562. 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) &&
  563. (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))
  564. {
  565. tmFrom.tm_year -= 1900;
  566. tmFrom.tm_mon -= 1;
  567. tbFrom.time = mktime(&tmFrom);
  568. tmTo.tm_year -= 1900;
  569. tmTo.tm_mon -= 1;
  570. tbTo.time = mktime(&tmTo);
  571. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  572. {
  573. if(maxProfile.ChargingProfileId == -1)
  574. DEBUG_INFO("MaxProfile found.\n");
  575. else
  576. DEBUG_INFO("MaxProfile updated.\n");
  577. // Required item
  578. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  579. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  580. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  581. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  582. 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++)
  583. {
  584. 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"));
  585. 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")));
  586. 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?
  587. 3:
  588. 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")));
  589. }
  590. // Optional item
  591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  592. {
  593. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  594. }
  595. else
  596. {
  597. sprintf((char*)maxProfile.ValidFrom, " ");
  598. }
  599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  600. {
  601. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  602. }
  603. else
  604. {
  605. sprintf((char*)maxProfile.ValidTo, " ");
  606. }
  607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  608. {
  609. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  610. }
  611. else
  612. {
  613. sprintf((char*)maxProfile.RecurrencyKind, " ");
  614. }
  615. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  616. {
  617. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  618. }
  619. else
  620. {
  621. maxProfile.TransactionId = -1;
  622. }
  623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  624. {
  625. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  626. }
  627. else
  628. {
  629. maxProfile.ChargingSchedule.Duration = -1;
  630. }
  631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  632. {
  633. 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")));
  634. }
  635. else
  636. {
  637. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  638. }
  639. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  640. {
  641. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  642. }
  643. else
  644. {
  645. maxProfile.ChargingSchedule.MinChargingRate = -1;
  646. }
  647. }
  648. }
  649. }
  650. else
  651. {
  652. if(maxProfile.ChargingProfileId == -1)
  653. DEBUG_INFO("MaxProfile found.\n");
  654. else
  655. DEBUG_INFO("MaxProfile updated.\n");
  656. // Required item
  657. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  658. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  659. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  660. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  661. 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++)
  662. {
  663. 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"));
  664. 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")));
  665. 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?
  666. 3:
  667. 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")));
  668. }
  669. // Optional item
  670. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  671. {
  672. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  673. }
  674. else
  675. {
  676. sprintf((char*)maxProfile.ValidFrom, " ");
  677. }
  678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  679. {
  680. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  681. }
  682. else
  683. {
  684. sprintf((char*)maxProfile.ValidTo, " ");
  685. }
  686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  687. {
  688. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  689. }
  690. else
  691. {
  692. sprintf((char*)maxProfile.RecurrencyKind, " ");
  693. }
  694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  695. {
  696. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  697. }
  698. else
  699. {
  700. maxProfile.TransactionId = -1;
  701. }
  702. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  703. {
  704. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  705. }
  706. else
  707. {
  708. maxProfile.ChargingSchedule.Duration = -1;
  709. }
  710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  711. {
  712. 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")));
  713. }
  714. else
  715. {
  716. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  717. }
  718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  719. {
  720. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  721. }
  722. else
  723. {
  724. maxProfile.ChargingSchedule.MinChargingRate = -1;
  725. }
  726. }
  727. }
  728. }
  729. json_object_put(obj);
  730. }
  731. fclose(fp);
  732. /*
  733. if(maxProfile.ChargingProfileId !=-1)
  734. {
  735. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  736. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  737. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  738. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  739. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  740. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  741. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  742. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  743. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  744. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  745. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  746. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  747. {
  748. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  749. {
  750. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  751. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  752. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  753. }
  754. }
  755. }
  756. else
  757. DEBUG_INFO("MaxProfile not found.\n");
  758. DEBUG_INFO("------------------------------------\n");*/
  759. }
  760. // Search default tx profile
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  762. if((access(profileFileName, F_OK))==-1)
  763. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  764. if((access(profileFileName, F_OK))!=-1)
  765. {
  766. fp = fopen(profileFileName, "r");
  767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  768. {
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  771. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  772. }
  773. defaultTxProfile.ChargingProfileId = -1;
  774. defaultTxProfile.StackLevel = -1;
  775. while(getline(&line, &len, fp) != -1)
  776. {
  777. json_object *obj = NULL;
  778. obj = json_tokener_parse(line);
  779. if(is_error(obj))
  780. {
  781. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  782. }
  783. else
  784. {
  785. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  786. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  787. )
  788. {
  789. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  790. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  791. )
  792. {
  793. struct tm tmFrom, tmTo;
  794. struct timeb tbFrom, tbTo;
  795. 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) &&
  796. (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))
  797. {
  798. tmFrom.tm_year -= 1900;
  799. tmFrom.tm_mon -= 1;
  800. tbFrom.time = mktime(&tmFrom);
  801. tmTo.tm_year -= 1900;
  802. tmTo.tm_mon -= 1;
  803. tbTo.time = mktime(&tmTo);
  804. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  805. {
  806. if(defaultTxProfile.ChargingProfileId == -1)
  807. DEBUG_INFO("TxDefaultProfile found.\n");
  808. else
  809. DEBUG_INFO("TxDefaultProfile updated.\n");
  810. // Required item
  811. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  812. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  813. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  814. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  815. 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++)
  816. {
  817. 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"));
  818. 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")));
  819. 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?
  820. 3:
  821. 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")));
  822. }
  823. // Optional item
  824. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  825. {
  826. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  827. }
  828. else
  829. {
  830. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  831. }
  832. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  833. {
  834. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  835. }
  836. else
  837. {
  838. sprintf((char*)defaultTxProfile.ValidTo, " ");
  839. }
  840. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  841. {
  842. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  843. }
  844. else
  845. {
  846. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  847. }
  848. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  849. {
  850. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  851. }
  852. else
  853. {
  854. defaultTxProfile.TransactionId = -1;
  855. }
  856. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  857. {
  858. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  859. }
  860. else
  861. {
  862. defaultTxProfile.ChargingSchedule.Duration = -1;
  863. }
  864. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  865. {
  866. 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")));
  867. }
  868. else
  869. {
  870. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  871. }
  872. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  873. {
  874. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  875. }
  876. else
  877. {
  878. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  879. }
  880. }
  881. }
  882. }
  883. else
  884. {
  885. if(defaultTxProfile.ChargingProfileId == -1)
  886. DEBUG_INFO("TxDefaultProfile found.\n");
  887. else
  888. DEBUG_INFO("TxDefaultProfile updated.\n");
  889. // Required item
  890. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  891. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  892. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  893. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  894. 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++)
  895. {
  896. 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"));
  897. 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")));
  898. 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?
  899. 3:
  900. 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")));
  901. }
  902. // Optional item
  903. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  904. {
  905. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  906. }
  907. else
  908. {
  909. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  910. }
  911. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  912. {
  913. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  914. }
  915. else
  916. {
  917. sprintf((char*)defaultTxProfile.ValidTo, " ");
  918. }
  919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  920. {
  921. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  922. }
  923. else
  924. {
  925. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  926. }
  927. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  928. {
  929. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  930. }
  931. else
  932. {
  933. defaultTxProfile.TransactionId = -1;
  934. }
  935. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  936. {
  937. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  938. }
  939. else
  940. {
  941. defaultTxProfile.ChargingSchedule.Duration = -1;
  942. }
  943. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  944. {
  945. 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")));
  946. }
  947. else
  948. {
  949. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  950. }
  951. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  952. {
  953. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  954. }
  955. else
  956. {
  957. maxProfile.ChargingSchedule.MinChargingRate = -1;
  958. }
  959. }
  960. }
  961. }
  962. json_object_put(obj);
  963. }
  964. fclose(fp);
  965. /*
  966. if(defaultTxProfile.ChargingProfileId != -1)
  967. {
  968. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  969. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  970. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  971. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  972. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  973. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  974. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  975. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  976. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  977. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  978. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  979. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  980. {
  981. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  982. {
  983. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  984. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  985. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  986. }
  987. }
  988. }
  989. else
  990. DEBUG_INFO("TxDefaultProfile not found.\n");
  991. DEBUG_INFO("------------------------------------\n");*/
  992. }
  993. // Search tx profile
  994. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  995. if((access(profileFileName, F_OK))!=-1)
  996. {
  997. fp = fopen(profileFileName, "r");
  998. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  999. {
  1000. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1001. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1002. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1003. }
  1004. txProfile.ChargingProfileId = -1;
  1005. txProfile.StackLevel = -1;
  1006. while(getline(&line, &len, fp) != -1)
  1007. {
  1008. json_object *obj = NULL;
  1009. obj = json_tokener_parse(line);
  1010. if(is_error(obj))
  1011. {
  1012. DEBUG_ERROR("Parse txProfile from file error.\n");
  1013. }
  1014. else
  1015. {
  1016. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1017. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1018. )
  1019. {
  1020. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1021. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1022. )
  1023. {
  1024. struct tm tmFrom, tmTo;
  1025. struct timeb tbFrom, tbTo;
  1026. 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) &&
  1027. (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))
  1028. {
  1029. tmFrom.tm_year -= 1900;
  1030. tmFrom.tm_mon -= 1;
  1031. tbFrom.time = mktime(&tmFrom);
  1032. tmTo.tm_year -= 1900;
  1033. tmTo.tm_mon -= 1;
  1034. tbTo.time = mktime(&tmTo);
  1035. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1036. {
  1037. if(txProfile.ChargingProfileId == -1)
  1038. DEBUG_INFO("TxProfile found.\n");
  1039. else
  1040. DEBUG_INFO("TxProfile updated.\n");
  1041. // Required item
  1042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1045. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1046. 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++)
  1047. {
  1048. 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"));
  1049. 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")));
  1050. 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?
  1051. 3:
  1052. 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")));
  1053. }
  1054. // Optional item
  1055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1056. {
  1057. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1058. }
  1059. else
  1060. {
  1061. sprintf((char*)txProfile.ValidFrom, " ");
  1062. }
  1063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1064. {
  1065. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)txProfile.ValidTo, " ");
  1070. }
  1071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1072. {
  1073. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1074. }
  1075. else
  1076. {
  1077. sprintf((char*)txProfile.RecurrencyKind, " ");
  1078. }
  1079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1080. {
  1081. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1082. }
  1083. else
  1084. {
  1085. txProfile.TransactionId = -1;
  1086. }
  1087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1088. {
  1089. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1090. }
  1091. else
  1092. {
  1093. txProfile.ChargingSchedule.Duration = -1;
  1094. }
  1095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1096. {
  1097. 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")));
  1098. }
  1099. else
  1100. {
  1101. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1102. }
  1103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1104. {
  1105. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1106. }
  1107. else
  1108. {
  1109. txProfile.ChargingSchedule.MinChargingRate = -1;
  1110. }
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. if(txProfile.ChargingProfileId == -1)
  1117. DEBUG_INFO("TxProfile found.\n");
  1118. else
  1119. DEBUG_INFO("TxProfile updated.\n");
  1120. // Required item
  1121. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1122. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1123. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1124. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1125. 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++)
  1126. {
  1127. 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"));
  1128. 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")));
  1129. 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?
  1130. 3:
  1131. 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")));
  1132. }
  1133. // Optional item
  1134. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1135. {
  1136. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1137. }
  1138. else
  1139. {
  1140. sprintf((char*)txProfile.ValidFrom, " ");
  1141. }
  1142. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1143. {
  1144. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1145. }
  1146. else
  1147. {
  1148. sprintf((char*)txProfile.ValidTo, " ");
  1149. }
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1151. {
  1152. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1153. }
  1154. else
  1155. {
  1156. sprintf((char*)txProfile.RecurrencyKind, " ");
  1157. }
  1158. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1159. {
  1160. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1161. }
  1162. else
  1163. {
  1164. txProfile.TransactionId = -1;
  1165. }
  1166. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1167. {
  1168. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1169. }
  1170. else
  1171. {
  1172. txProfile.ChargingSchedule.Duration = -1;
  1173. }
  1174. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1175. {
  1176. 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")));
  1177. }
  1178. else
  1179. {
  1180. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1181. }
  1182. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1183. {
  1184. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1185. }
  1186. else
  1187. {
  1188. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1189. }
  1190. }
  1191. }
  1192. }
  1193. json_object_put(obj);
  1194. }
  1195. fclose(fp);
  1196. /*
  1197. if(defaultTxProfile.ChargingProfileId != -1)
  1198. {
  1199. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1200. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1201. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1202. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1203. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1204. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1205. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1206. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1207. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1208. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1209. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1210. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1211. {
  1212. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1213. {
  1214. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1215. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1216. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1217. }
  1218. }
  1219. }
  1220. else
  1221. DEBUG_INFO("TxProfile not found.\n");*/
  1222. }
  1223. /*
  1224. * Align found profile start schedule & periods
  1225. */
  1226. //DEBUG_INFO("====================================\n");
  1227. /*
  1228. // For local test usage, force modify found profile start schedule info
  1229. 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);
  1230. 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);
  1231. 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);
  1232. */
  1233. if(maxProfile.ChargingProfileId != -1)
  1234. {
  1235. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1236. {
  1237. if(maxProfile.ChargingSchedule.Duration != -1)
  1238. {
  1239. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1240. 0:
  1241. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1242. }
  1243. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1244. {
  1245. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1246. {
  1247. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1248. 0:
  1249. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1250. }
  1251. }
  1252. }
  1253. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1254. {
  1255. if(maxProfile.ChargingSchedule.Duration != -1)
  1256. {
  1257. 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?
  1258. 0:
  1259. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1260. }
  1261. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1262. {
  1263. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1264. {
  1265. 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?
  1266. 0:
  1267. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1268. }
  1269. }
  1270. }
  1271. else
  1272. {
  1273. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1274. {
  1275. if(maxProfile.ChargingSchedule.Duration != -1)
  1276. {
  1277. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1278. 0:
  1279. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1280. }
  1281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1282. {
  1283. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1284. {
  1285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1286. 0:
  1287. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1288. }
  1289. }
  1290. }
  1291. else
  1292. {
  1293. if(maxProfile.ChargingSchedule.Duration != -1)
  1294. {
  1295. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1296. 0:
  1297. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1298. }
  1299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1300. {
  1301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1302. {
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1304. 0:
  1305. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1306. }
  1307. }
  1308. }
  1309. }
  1310. /*
  1311. DEBUG_INFO("MaxProfile after align.\n");
  1312. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1313. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1314. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1315. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1316. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1317. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1318. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1319. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1320. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1321. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1322. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1323. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1324. {
  1325. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1326. {
  1327. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1328. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1329. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1330. }
  1331. }
  1332. DEBUG_INFO("------------------------------------\n");*/
  1333. }
  1334. if(defaultTxProfile.ChargingProfileId != -1)
  1335. {
  1336. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1337. {
  1338. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1339. {
  1340. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1341. 0:
  1342. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1343. }
  1344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1345. {
  1346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1347. {
  1348. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1349. 0:
  1350. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1351. }
  1352. }
  1353. }
  1354. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1355. {
  1356. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1357. {
  1358. 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?
  1359. 0:
  1360. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1361. }
  1362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1365. {
  1366. 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?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. }
  1371. }
  1372. else
  1373. {
  1374. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1375. {
  1376. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1377. {
  1378. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1379. 0:
  1380. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1381. }
  1382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1383. {
  1384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1385. {
  1386. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1387. 0:
  1388. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1389. }
  1390. }
  1391. }
  1392. else
  1393. {
  1394. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1395. {
  1396. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1397. 0:
  1398. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1399. }
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1403. {
  1404. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1405. 0:
  1406. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1407. }
  1408. }
  1409. }
  1410. }
  1411. /*
  1412. DEBUG_INFO("defaultTxProfile after align.\n");
  1413. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1414. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1415. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1416. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1417. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1418. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1419. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1420. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1421. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1422. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1423. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1424. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1425. {
  1426. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1427. {
  1428. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1429. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1430. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1431. }
  1432. }
  1433. DEBUG_INFO("------------------------------------\n");*/
  1434. }
  1435. if(txProfile.ChargingProfileId != -1)
  1436. {
  1437. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1438. {
  1439. if(txProfile.ChargingSchedule.Duration != -1)
  1440. {
  1441. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1442. 0:
  1443. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1444. }
  1445. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1446. {
  1447. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1448. {
  1449. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1450. 0:
  1451. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1452. }
  1453. }
  1454. }
  1455. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1456. {
  1457. if(txProfile.ChargingSchedule.Duration != -1)
  1458. {
  1459. 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?
  1460. 0:
  1461. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1462. }
  1463. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1464. {
  1465. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1466. {
  1467. 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?
  1468. 0:
  1469. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1470. }
  1471. }
  1472. }
  1473. else
  1474. {
  1475. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1476. {
  1477. if(txProfile.ChargingSchedule.Duration != -1)
  1478. {
  1479. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1480. 0:
  1481. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1482. }
  1483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1484. {
  1485. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1486. {
  1487. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1488. 0:
  1489. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1490. }
  1491. }
  1492. }
  1493. else
  1494. {
  1495. if(txProfile.ChargingSchedule.Duration != -1)
  1496. {
  1497. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1498. 0:
  1499. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1500. }
  1501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1502. {
  1503. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1504. {
  1505. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1506. 0:
  1507. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1508. }
  1509. }
  1510. }
  1511. }
  1512. /*
  1513. DEBUG_INFO("txProfile after align.\n");
  1514. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1515. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1516. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1517. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1518. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1519. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1520. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1521. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1522. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1523. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1524. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1525. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1526. {
  1527. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1528. {
  1529. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1530. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1531. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1532. }
  1533. }*/
  1534. }
  1535. /*
  1536. * Merge to conposite schedule
  1537. */
  1538. //DEBUG_INFO("====================================\n");
  1539. // Find each profile period quantity
  1540. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1543. limitMax = idx+1;
  1544. }
  1545. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1546. {
  1547. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1548. limitDef = idx+1;
  1549. }
  1550. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1551. {
  1552. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1553. limitTx = idx+1;
  1554. }
  1555. // TxProfile found, composite schedule based on it
  1556. if(txProfile.ChargingProfileId != -1)
  1557. {
  1558. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1559. {
  1560. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1561. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1562. {
  1563. if(maxProfile.ChargingProfileId != -1)
  1564. {
  1565. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1566. {
  1567. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1568. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1569. {
  1570. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1571. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1572. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1573. }
  1574. if(idxMaxPeriod == (limitMax-1))
  1575. {
  1576. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1577. {
  1578. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1579. {
  1580. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1581. compositePeriodIdx++;
  1582. }
  1583. else
  1584. {
  1585. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1586. }
  1587. }
  1588. }
  1589. }
  1590. }
  1591. else
  1592. {
  1593. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1594. {
  1595. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1596. compositePeriodIdx++;
  1597. }
  1598. else
  1599. {
  1600. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1601. }
  1602. }
  1603. }
  1604. if(idxTxPeriod == (limitTx-1))
  1605. {
  1606. if(defaultTxProfile.ChargingProfileId != -1)
  1607. {
  1608. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1609. {
  1610. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1611. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1612. {
  1613. if(maxProfile.ChargingProfileId != -1)
  1614. {
  1615. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1616. {
  1617. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1618. {
  1619. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1620. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1621. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1622. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1623. {
  1624. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1625. {
  1626. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1627. compositePeriodIdx++;
  1628. }
  1629. else
  1630. {
  1631. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1632. }
  1633. }
  1634. break;
  1635. }
  1636. }
  1637. }
  1638. else
  1639. {
  1640. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1641. {
  1642. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1643. compositePeriodIdx++;
  1644. }
  1645. else
  1646. {
  1647. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1657. else if(defaultTxProfile.ChargingProfileId != -1)
  1658. {
  1659. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1660. {
  1661. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1662. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1663. {
  1664. if(maxProfile.ChargingProfileId != -1)
  1665. {
  1666. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1667. {
  1668. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1669. {
  1670. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1671. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1672. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1673. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1674. {
  1675. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1676. {
  1677. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1678. compositePeriodIdx++;
  1679. }
  1680. else
  1681. {
  1682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1683. }
  1684. }
  1685. break;
  1686. }
  1687. }
  1688. }
  1689. else
  1690. {
  1691. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1694. compositePeriodIdx++;
  1695. }
  1696. else
  1697. {
  1698. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. // Fill other period by MaxProfile
  1705. if(maxProfile.ChargingProfileId != -1)
  1706. {
  1707. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1708. {
  1709. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1710. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  1711. {
  1712. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1713. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1714. {
  1715. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1716. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1717. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1718. }
  1719. if(idxMaxPeriod == (limitMax-1))
  1720. {
  1721. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  1722. {
  1723. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1724. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1725. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1726. }
  1727. if(tmpPeriod.Limit != -1)
  1728. {
  1729. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1730. {
  1731. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1732. {
  1733. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1734. compositePeriodIdx++;
  1735. }
  1736. else
  1737. {
  1738. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1747. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1748. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1752. {
  1753. compositeProfile->ChargingProfileId = 1;
  1754. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1755. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1756. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1757. }
  1758. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1759. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1760. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1761. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1762. }
  1763. if(line)
  1764. free(line);
  1765. }
  1766. //==========================================
  1767. // Init all share memory
  1768. //==========================================
  1769. int InitShareMemory()
  1770. {
  1771. int result = PASS;
  1772. int MeterSMId;
  1773. //creat ShmSysConfigAndInfo
  1774. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1775. {
  1776. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1777. result = FAIL;
  1778. }
  1779. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1780. {
  1781. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1782. result = FAIL;
  1783. }
  1784. else
  1785. {}
  1786. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1787. {
  1788. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1789. result = FAIL;
  1790. }
  1791. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1792. {
  1793. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1794. result = FAIL;
  1795. }
  1796. else
  1797. {}
  1798. //creat ShmPsuData
  1799. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1800. {
  1801. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1802. result = FAIL;
  1803. }
  1804. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1805. {
  1806. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1807. result = FAIL;
  1808. }
  1809. else
  1810. {}
  1811. //creat ShmOCPP16Data
  1812. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1813. {
  1814. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1815. result = FAIL;
  1816. }
  1817. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1818. {
  1819. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1820. result = FAIL;
  1821. }
  1822. else
  1823. {}
  1824. /****************************** For Initial Settings************************************************/
  1825. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1826. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1827. // allocate Configuration memory address
  1828. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1829. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1830. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1831. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1832. //offline MeterValue Interval
  1833. TempMeterValueInterval = 0;
  1834. return result;
  1835. }
  1836. int ProcessShareMemory()
  1837. {
  1838. if(InitShareMemory() == FAIL)
  1839. {
  1840. DEBUG_ERROR("InitShareMemory NG\n");
  1841. if(ShmStatusCodeData!=NULL)
  1842. {
  1843. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1844. }
  1845. sleep(5);
  1846. return FAIL;
  1847. }
  1848. return PASS;
  1849. }
  1850. //---------------------common routine---------------------------//
  1851. int isOFFline(void)
  1852. {
  1853. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1854. {
  1855. if(TempMeterValueInterval >= 2 )
  1856. {
  1857. TempMeterValueInterval = 0;
  1858. return TRUE;
  1859. }
  1860. else
  1861. {
  1862. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1863. return FALSE;
  1864. }
  1865. }
  1866. else
  1867. {
  1868. return FALSE;
  1869. }
  1870. }
  1871. //---------------------------------------------
  1872. // new:
  1873. // enum SYSTEM_STATUS
  1874. // {
  1875. // SYS_MODE_BOOTING = 0,
  1876. // SYS_MODE_IDLE = 1,
  1877. // SYS_MODE_AUTHORIZING = 2,
  1878. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1879. // SYS_MODE_REASSIGN = 4,
  1880. // SYS_MODE_PREPARING = 5,
  1881. // SYS_MODE_PREPARE_FOR_EV = 6,
  1882. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1883. // SYS_MODE_CHARGING = 8,
  1884. // SYS_MODE_TERMINATING = 9,
  1885. // SYS_MODE_COMPLETE = 10,
  1886. // SYS_MODE_ALARM = 11,
  1887. // SYS_MODE_FAULT = 12,
  1888. // SYS_MODE_RESERVATION = 13,
  1889. // SYS_MODE_BOOKING = 14,
  1890. // SYS_MODE_MAINTAIN = 15,
  1891. // SYS_MODE_DEBUG = 16,
  1892. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1893. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1894. // SYS_MODE_UPDATE = 19
  1895. // };
  1896. //
  1897. //
  1898. //-----------------------------------------
  1899. void CheckSystemValue(void)
  1900. {
  1901. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1902. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1903. char filenmae[100]={0};
  1904. char str[100]={0};
  1905. int tempIndex = 0;
  1906. //===============================
  1907. // send Heartbeat
  1908. //===============================
  1909. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1910. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1911. {
  1912. clientTime.Heartbeat=time((time_t*)NULL);
  1913. if(server_sign == TRUE)
  1914. {
  1915. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1916. }
  1917. else
  1918. {
  1919. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  1920. }
  1921. }
  1922. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1923. {
  1924. //parameter for test
  1925. sendHeartbeatRequest(0);
  1926. //==============================================
  1927. // Reset Waiting Time
  1928. //==============================================
  1929. clientTime.Heartbeat=time((time_t*)NULL);
  1930. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1931. }
  1932. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1933. {
  1934. //===============================
  1935. // CSU Trigger Reset Conf
  1936. //===============================
  1937. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1938. {
  1939. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1940. }
  1941. //===============================
  1942. // CSU Trigger Authorize Request
  1943. //===============================
  1944. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1945. {
  1946. sendAuthorizeRequest(0);
  1947. authorizeRetryTimes = authorizeRetryTimes + 1;
  1948. if(authorizeRetryTimes < 3)
  1949. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1950. }
  1951. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  1952. {
  1953. authorizeRetryTimes = 0;
  1954. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1955. server_sign = FALSE;
  1956. }
  1957. 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))
  1958. {
  1959. sendAuthorizeRequest(0);
  1960. }
  1961. //===============================
  1962. // CSU Trigger Smart Charging Profilw
  1963. //===============================
  1964. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1965. {
  1966. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1967. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  1968. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1969. }
  1970. //==============================================
  1971. // Charger start transaction
  1972. //==============================================
  1973. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1974. {
  1975. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1976. sendStartTransactionRequest(gun_index);
  1977. clientTime.StartTransaction = time((time_t*)NULL);
  1978. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1979. }
  1980. //==============================================
  1981. // Charger stop transaction
  1982. //==============================================
  1983. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1984. {
  1985. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1986. sendStopTransactionRequest(gun_index);
  1987. clientTime.StopTransaction = time((time_t*)NULL);
  1988. }
  1989. //==============================================
  1990. // Charger status report
  1991. //==============================================
  1992. //--- Check Mode Change ---//
  1993. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1994. if(gunType[gun_index] == 'J')
  1995. {
  1996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1997. {
  1998. tempIndex = ((gun_index==2) ? 1: 0);
  1999. }
  2000. else
  2001. {
  2002. tempIndex = gun_index;
  2003. }
  2004. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2005. {
  2006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2007. {
  2008. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2009. {
  2010. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2011. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2012. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2013. statusModeChage[gun_index] = TRUE;
  2014. }
  2015. #if 1 // for TempStopTransaction
  2016. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2017. {
  2018. checkTempStopTransaction(gun_index);
  2019. }
  2020. #endif
  2021. }
  2022. }
  2023. }
  2024. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2025. {
  2026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2027. {
  2028. tempIndex = ((gun_index==2) ? 1: 0);
  2029. }
  2030. else
  2031. {
  2032. tempIndex = gun_index;
  2033. }
  2034. for (int index = 0; index < CCS_QUANTITY; index++)
  2035. {
  2036. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2037. {
  2038. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2039. {
  2040. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2041. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2042. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2043. statusModeChage[gun_index] = TRUE;
  2044. }
  2045. #if 1 // for TempStopTransaction
  2046. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2047. {
  2048. checkTempStopTransaction(gun_index);
  2049. }
  2050. #endif
  2051. }
  2052. }
  2053. }
  2054. else if(gunType[gun_index] == 'G')
  2055. {
  2056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2057. {
  2058. tempIndex = ((gun_index==2) ? 1: 0);
  2059. }
  2060. else
  2061. {
  2062. tempIndex = gun_index;
  2063. }
  2064. for (int index = 0; index < GB_QUANTITY; index++)
  2065. {
  2066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2067. {
  2068. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2069. {
  2070. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2071. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2072. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2073. statusModeChage[gun_index] = TRUE;
  2074. }
  2075. #if 1 // for TempStopTransaction
  2076. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2077. {
  2078. checkTempStopTransaction(gun_index);
  2079. }
  2080. #endif
  2081. }
  2082. }
  2083. }
  2084. else
  2085. {
  2086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2087. {
  2088. tempIndex = 2;
  2089. }
  2090. else
  2091. {
  2092. tempIndex = gun_index;
  2093. }
  2094. for (int index = 0; index < AC_QUANTITY; index++)
  2095. {
  2096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2097. {
  2098. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2099. {
  2100. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2101. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2102. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2103. statusModeChage[gun_index] = TRUE;
  2104. }
  2105. #if 1 // for TempStopTransaction
  2106. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2107. {
  2108. checkTempStopTransaction(gun_index);
  2109. }
  2110. #endif
  2111. }
  2112. }// END
  2113. }
  2114. if(isWebsocketSendable &&
  2115. ((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)))) )
  2116. {
  2117. if(SystemInitial > 0)
  2118. SystemInitial -= 1;
  2119. sendStatusNotificationRequest(gun_index);
  2120. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2121. statusModeChage[gun_index] = FALSE;
  2122. }
  2123. //==============================================
  2124. // Meter report
  2125. //==============================================
  2126. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2127. (((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)))
  2128. {
  2129. //check Transaction active
  2130. if(gunType[gun_index] == 'J')
  2131. {
  2132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2133. {
  2134. tempIndex = ((gun_index==2) ? 1: 0);
  2135. }
  2136. else
  2137. {
  2138. tempIndex = gun_index;
  2139. }
  2140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2141. {
  2142. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2143. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2144. {
  2145. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2146. {
  2147. reqSampleMeter[gun_index] = 1;
  2148. }
  2149. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2150. {
  2151. reqClockAlignMeter[gun_index] = 1;
  2152. }
  2153. }
  2154. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2155. {
  2156. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2157. if((access(filenmae,F_OK))!=-1)
  2158. {
  2159. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2160. sprintf(str,"rm -f %s",filenmae);
  2161. system(str);
  2162. }
  2163. }
  2164. }// End for CHAdeMO
  2165. }
  2166. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2167. {
  2168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2169. {
  2170. tempIndex = ((gun_index==2) ? 1: 0);
  2171. }
  2172. else
  2173. {
  2174. tempIndex = gun_index;
  2175. }
  2176. for (int index = 0; index < CCS_QUANTITY; index++)
  2177. {
  2178. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2179. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2180. {
  2181. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2182. {
  2183. reqSampleMeter[gun_index] = 1;
  2184. }
  2185. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2186. {
  2187. reqClockAlignMeter[gun_index] = 1;
  2188. }
  2189. }
  2190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2191. {
  2192. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2193. if((access(filenmae,F_OK))!=-1)
  2194. {
  2195. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2196. sprintf(str,"rm -f %s",filenmae);
  2197. system(str);
  2198. }
  2199. }
  2200. } // End for CCS
  2201. }
  2202. else if(gunType[gun_index] == 'G')
  2203. {
  2204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2205. {
  2206. tempIndex = ((gun_index==2) ? 1: 0);
  2207. }
  2208. else
  2209. {
  2210. tempIndex = gun_index;
  2211. }
  2212. for (int index = 0; index < GB_QUANTITY; index++)
  2213. {
  2214. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2215. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2216. {
  2217. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2218. {
  2219. reqSampleMeter[gun_index] = 1;
  2220. }
  2221. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2222. {
  2223. reqClockAlignMeter[gun_index] = 1;
  2224. }
  2225. }
  2226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2227. {
  2228. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2229. if((access(filenmae,F_OK))!=-1)
  2230. {
  2231. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2232. sprintf(str,"rm -f %s",filenmae);
  2233. system(str);
  2234. }
  2235. }
  2236. }// End for GB
  2237. }
  2238. else
  2239. {
  2240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2241. {
  2242. tempIndex = 2;
  2243. }
  2244. else
  2245. {
  2246. tempIndex = gun_index;
  2247. }
  2248. for (int index = 0; index < AC_QUANTITY; index++)
  2249. {
  2250. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2251. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2252. {
  2253. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2254. {
  2255. reqSampleMeter[gun_index] = 1;
  2256. }
  2257. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2258. {
  2259. reqClockAlignMeter[gun_index] = 1;
  2260. }
  2261. }
  2262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2263. {
  2264. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2265. if((access(filenmae,F_OK))!=-1)
  2266. {
  2267. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2268. sprintf(str,"rm -f %s",filenmae);
  2269. system(str);
  2270. }
  2271. }
  2272. }//End for AC
  2273. }
  2274. if(reqSampleMeter[gun_index] == 1)
  2275. {
  2276. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2277. storeTempStopTransaction(gun_index);
  2278. }
  2279. else if(reqClockAlignMeter[gun_index] == 1)
  2280. {
  2281. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2282. }
  2283. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2284. sleep(1);
  2285. }
  2286. //==============================================
  2287. // Check Connector reserved
  2288. //==============================================
  2289. //===============================
  2290. // Check if Reserve is expired
  2291. //===============================
  2292. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2293. {
  2294. double diff_t;
  2295. struct tm tp;
  2296. // current time
  2297. time_t t = time(NULL);
  2298. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2299. tp.tm_isdst = -1;
  2300. time_t utc = mktime(&tp);
  2301. diff_t = difftime(utc, t);
  2302. if(diff_t <= 0)
  2303. {
  2304. DEBUG_INFO("reserve expired.\n");
  2305. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2306. }
  2307. }//END OF Check if Reserve is expired
  2308. //==========================================
  2309. // csu trigger FirmwareStatusNotificationReq
  2310. //==========================================
  2311. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2312. {
  2313. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2314. }
  2315. //==========================================
  2316. // csu trigger CancelReservationConf
  2317. //==========================================
  2318. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2319. {
  2320. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2321. }
  2322. //==========================================
  2323. // csu trigger ChangeAvailabilityConf
  2324. //==========================================
  2325. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2326. {
  2327. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2328. }
  2329. //==========================================
  2330. // csu trigger UnlockConnectorConf
  2331. //==========================================
  2332. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2333. {
  2334. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2335. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2336. }
  2337. //==========================================
  2338. // csu trigger ReserveNowConf
  2339. //==========================================
  2340. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2341. {
  2342. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2343. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2344. }
  2345. //==========================================
  2346. // csu trigger DataTransferReq
  2347. //==========================================
  2348. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2349. {
  2350. sendDataTransferRequest(gun_index);
  2351. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2352. }
  2353. }
  2354. }
  2355. //==========================================
  2356. // send request routine
  2357. //==========================================
  2358. int sendAuthorizeRequest(int gun_index)
  2359. {
  2360. mtrace();
  2361. int result = FAIL;
  2362. char message[100]={0};
  2363. char guid[37];
  2364. char tempdata[65]={0};
  2365. DEBUG_INFO("sendAuthorizeRequest...\n");
  2366. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2367. //Local Authorize
  2368. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2369. {
  2370. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2371. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2372. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2373. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2374. result = PASS;
  2375. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2376. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2377. authorizeRetryTimes = 0;
  2378. return result;
  2379. }
  2380. 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))||
  2381. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2382. {
  2383. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2384. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2385. {
  2386. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2387. {
  2388. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2389. }
  2390. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2391. {
  2392. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2393. }
  2394. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2395. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2396. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2397. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2398. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2399. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2400. authorizeRetryTimes = 0;
  2401. return result;
  2402. }
  2403. else
  2404. {
  2405. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2407. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2408. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2409. result = PASS;
  2410. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2411. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2412. authorizeRetryTimes = 0;
  2413. return result;
  2414. }
  2415. }
  2416. //initailize struct Authorize
  2417. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2418. //get data from shared memory
  2419. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2420. random_uuid(guid);
  2421. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2422. LWS_Send(message);
  2423. sprintf(tempdata, "Authorize,%d", gun_index);
  2424. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2425. {
  2426. result = PASS;
  2427. DEBUG_INFO("Authorize mapItem pass\n");
  2428. }
  2429. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2430. return result;
  2431. }
  2432. int sendBootNotificationRequest(void)
  2433. {
  2434. mtrace();
  2435. int result = FAIL;
  2436. char message[500]={0}, payload[700]={0};
  2437. char guid[37]={0};
  2438. char tempdata[65]={0};
  2439. /*
  2440. int IsGunCharging = FALSE;
  2441. //check Transaction active
  2442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2443. {
  2444. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2445. {
  2446. IsGunCharging = TRUE;
  2447. }
  2448. }
  2449. for (int index = 0; index < CCS_QUANTITY; index++)
  2450. {
  2451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2452. {
  2453. IsGunCharging = TRUE;
  2454. }
  2455. }
  2456. for (int index = 0; index < GB_QUANTITY; index++)
  2457. {
  2458. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2459. {
  2460. IsGunCharging = TRUE;
  2461. }
  2462. }
  2463. for (int index = 0; index < AC_QUANTITY; index++)
  2464. {
  2465. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2466. {
  2467. IsGunCharging = TRUE;
  2468. }
  2469. }
  2470. if(IsGunCharging == TRUE)
  2471. {
  2472. server_sign = TRUE;
  2473. return result;
  2474. }
  2475. */
  2476. // Fill BootNotification fields
  2477. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2478. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2479. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2480. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2481. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2482. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2483. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2484. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2485. ShmOCPP16Data->ChargeBoxId
  2486. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2487. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2488. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2489. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2490. ,ShmOCPP16Data->BootNotification.CpIccid
  2491. ,ShmOCPP16Data->BootNotification.CpImsi);
  2492. random_uuid(guid);
  2493. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2494. LWS_Send(message);
  2495. sprintf(tempdata, "BootNotification,0");
  2496. 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*/)
  2497. {
  2498. result = PASS;
  2499. }
  2500. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2501. strcpy(queuedata,message);
  2502. return result;
  2503. }
  2504. int sendDataTransferRequest(int gun_index)
  2505. {
  2506. mtrace();
  2507. char message[1000]={0};
  2508. char guid[37]={0};
  2509. char tempdata[65]={0};
  2510. int result = FAIL;
  2511. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2512. random_uuid(guid);
  2513. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2514. MESSAGE_TYPE_CALL,
  2515. guid,
  2516. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2517. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2518. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2519. LWS_Send(message);
  2520. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2521. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2522. {
  2523. result = PASS;
  2524. DEBUG_INFO("DataTransfer mapItem pass\n");
  2525. }
  2526. return result;
  2527. }
  2528. int sendDiagnosticsStatusNotificationRequest(char *status)
  2529. {
  2530. mtrace();
  2531. int result = FAIL;
  2532. char message[110]={0};
  2533. char guid[37]={0};
  2534. char tempdata[65]={0};
  2535. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2536. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2537. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2538. random_uuid(guid);
  2539. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2540. LWS_Send(message);
  2541. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2542. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2543. {
  2544. result = PASS;
  2545. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2546. }
  2547. //#ifdef SystemLogMessage
  2548. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2549. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2550. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2551. //#endif
  2552. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2553. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2554. //record status
  2555. if(strcmp(status,"Idle")==0)
  2556. {
  2557. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2558. }
  2559. else if(strcmp(status,"Uploaded")==0)
  2560. {
  2561. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2562. }
  2563. else if(strcmp(status,"UploadFailed")==0)
  2564. {
  2565. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2566. }
  2567. else if(strcmp(status,"Uploading")==0)
  2568. {
  2569. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2570. }
  2571. return result;
  2572. }
  2573. int sendFirmwareStatusNotificationRequest(char *status)
  2574. {
  2575. mtrace();
  2576. int result = FAIL;
  2577. char message[110]={0};
  2578. char guid[37]={0};
  2579. char tempdata[65]={0};
  2580. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2581. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2582. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2583. random_uuid(guid);
  2584. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2585. LWS_Send(message);
  2586. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2587. 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*/)
  2588. {
  2589. result = PASS;
  2590. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2591. }
  2592. //#ifdef SystemLogMessage
  2593. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2594. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2595. //#endif
  2596. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2597. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2598. //record status
  2599. if(strcmp(status,"Downloaded")==0)
  2600. {
  2601. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2602. }
  2603. else if(strcmp(status,"DownloadFailed")==0)
  2604. {
  2605. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2606. }
  2607. else if(strcmp(status,"Downloading")==0)
  2608. {
  2609. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2610. }
  2611. else if(strcmp(status,"Idle")==0)
  2612. {
  2613. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2614. }
  2615. else if(strcmp(status,"InstallationFailed")==0)
  2616. {
  2617. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2618. }
  2619. else if(strcmp(status,"Installing")==0)
  2620. {
  2621. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2622. }
  2623. else if(strcmp(status,"Installed")==0)
  2624. {
  2625. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2626. }
  2627. return result;
  2628. }
  2629. int sendHeartbeatRequest(int gun_index)
  2630. {
  2631. mtrace();
  2632. int result = FAIL;
  2633. char message[80]={0};
  2634. char guid[37]={0};
  2635. char tempdata[65]={0};
  2636. random_uuid(guid);
  2637. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2638. , MESSAGE_TYPE_CALL
  2639. , guid );
  2640. LWS_Send(message);
  2641. sprintf(tempdata, "Heartbeat,%d", 0);
  2642. 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*/)
  2643. {
  2644. result = PASS;
  2645. }
  2646. return result;
  2647. }
  2648. int sendStartTransactionRequest(int gun_index)
  2649. {
  2650. mtrace();
  2651. int result = FAIL;
  2652. char message[250]={0};
  2653. char guid[37]={0};
  2654. struct timeval tmnow;
  2655. struct tm *tm;
  2656. char buf[28];//, usec_buf[6];
  2657. char tempdata[65]={0};
  2658. int tempIndex = 0;
  2659. DEBUG_INFO("sendStartTransactionRequest...\n");
  2660. gettimeofday(&tmnow, NULL);
  2661. time_t t;
  2662. t = time(NULL);
  2663. /*UTC time and date*/
  2664. tm = gmtime(&t);
  2665. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2666. #if 0 // remove temporally
  2667. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2668. strcat(buf,".");
  2669. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2670. strcat(buf,usec_buf);
  2671. #endif
  2672. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2673. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2674. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2675. // clear StartTransaction Response
  2676. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2677. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2678. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2679. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2680. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2681. if(gunType[gun_index] == 'J')
  2682. {
  2683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2684. {
  2685. tempIndex = ((gun_index==2) ? 1: 0);
  2686. }
  2687. else
  2688. {
  2689. tempIndex = gun_index;
  2690. }
  2691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2692. {
  2693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2694. {
  2695. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2696. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2697. }
  2698. }
  2699. }
  2700. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2701. {
  2702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2703. {
  2704. tempIndex = ((gun_index==2) ? 1: 0);
  2705. }
  2706. else
  2707. {
  2708. tempIndex = gun_index;
  2709. }
  2710. for (int index = 0; index < CCS_QUANTITY; index++)
  2711. {
  2712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2713. {
  2714. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2715. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2716. }
  2717. }
  2718. }
  2719. else if(gunType[gun_index] == 'G')
  2720. {
  2721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2722. {
  2723. tempIndex = ((gun_index==2) ? 1: 0);
  2724. }
  2725. else
  2726. {
  2727. tempIndex = gun_index;
  2728. }
  2729. for (int index = 0; index < GB_QUANTITY; index++)
  2730. {
  2731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2732. {
  2733. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2734. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2735. }
  2736. }
  2737. }
  2738. else
  2739. {
  2740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2741. {
  2742. tempIndex = 2;
  2743. }
  2744. else
  2745. {
  2746. tempIndex = gun_index;
  2747. }
  2748. for (int index = 0; index < AC_QUANTITY; index++)
  2749. {
  2750. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2751. {
  2752. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2753. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2754. }
  2755. }
  2756. }
  2757. random_uuid(guid);
  2758. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2759. {
  2760. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2761. , gun_index +1
  2762. , MESSAGE_TYPE_CALL
  2763. , guid
  2764. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2765. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2766. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2767. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2768. }
  2769. else
  2770. {
  2771. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2772. , gun_index +1
  2773. , MESSAGE_TYPE_CALL
  2774. , guid
  2775. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2776. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2777. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2778. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2779. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2780. }
  2781. #if 1
  2782. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2783. 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*/)
  2784. {
  2785. result = PASS;
  2786. }
  2787. #endif
  2788. strcpy(queuedata, message);
  2789. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2790. /*
  2791. if(GetTransactionQueueNum() == 1)
  2792. {
  2793. LWS_Send(message + 2);
  2794. }*/
  2795. return result;
  2796. }
  2797. int sendStatusNotificationRequest(int gun_index)
  2798. {
  2799. mtrace();
  2800. int result = FAIL;
  2801. char message[600]={0};
  2802. char guid[37];
  2803. int currentStatus = 0;
  2804. struct timeval tmnow;
  2805. struct tm *tm;
  2806. char buf[28];//, usec_buf[6];
  2807. char tempdata[65]={0};
  2808. int tempIndex = 0;
  2809. gettimeofday(&tmnow, NULL);
  2810. time_t t;
  2811. t = time(NULL);
  2812. /*UTC time and date*/
  2813. tm = gmtime(&t);
  2814. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2815. #if 0 // remove temporally
  2816. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2817. strcat(buf,".");
  2818. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2819. strcat(buf,usec_buf);
  2820. #endif
  2821. printf("%s",buf);
  2822. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2823. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2824. // it's option
  2825. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2826. /*
  2827. enum _SYSTEM_STATUS
  2828. {
  2829. S_BOOTING = 0,
  2830. S_IDLE, = 1
  2831. S_AUTHORIZING, =2
  2832. S_REASSIGN_CHECK, =3
  2833. S_REASSIGN, =4
  2834. S_PRECHARGE, =5
  2835. S_PREPARING_FOR_EV, =6
  2836. S_PREPARING_FOR_EVSE, =7
  2837. S_CHARGING, =8
  2838. S_TERMINATING, =9
  2839. S_COMPLETE, =10
  2840. S_ALARM, =11
  2841. S_FAULT =12
  2842. }
  2843. */
  2844. //check Transaction active
  2845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2846. if(gunType[gun_index] == 'J')
  2847. {
  2848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2849. {
  2850. tempIndex = ((gun_index==2) ? 1: 0);
  2851. }
  2852. else
  2853. {
  2854. tempIndex = gun_index;
  2855. }
  2856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2857. {
  2858. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2859. {
  2860. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2861. {
  2862. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2863. {
  2864. currentStatus = 1; //OCPP Status: Preparing
  2865. }
  2866. else
  2867. {
  2868. currentStatus = 0; //OCPP Status: Available
  2869. }
  2870. }
  2871. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2872. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2873. ) //S_PRECHARGE
  2874. {
  2875. currentStatus = 1; //OCPP Status: Preparing
  2876. }
  2877. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2878. {
  2879. currentStatus = 2; //OCPP Status: Charging
  2880. }
  2881. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2882. {
  2883. currentStatus = 5; //OCPP Status: Finishing
  2884. }
  2885. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2886. {
  2887. currentStatus = 4; //OCPP Status: SuspendedEV
  2888. }
  2889. 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
  2890. {
  2891. currentStatus = 7; //OCPP Status: Unavailable
  2892. }
  2893. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2894. {
  2895. currentStatus = 8; //OCPP Status: Faulted
  2896. }
  2897. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2898. {
  2899. currentStatus = 6; //OCPP Status: Reserved
  2900. }
  2901. } //end of the same index
  2902. }//end of for CHAdeMO_QUANTITY
  2903. }
  2904. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2905. {
  2906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2907. {
  2908. tempIndex = ((gun_index==2) ? 1: 0);
  2909. }
  2910. else
  2911. {
  2912. tempIndex = gun_index;
  2913. }
  2914. for (int index = 0; index < CCS_QUANTITY; index++)
  2915. {
  2916. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2917. {
  2918. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2919. {
  2920. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  2921. {
  2922. currentStatus = 1; //OCPP Status: Preparing
  2923. }
  2924. else
  2925. {
  2926. currentStatus = 0; //OCPP Status: Available
  2927. }
  2928. }
  2929. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2930. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2931. ) //S_PRECHARGE
  2932. {
  2933. currentStatus = 1; //OCPP Status: Preparing
  2934. }
  2935. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2936. {
  2937. currentStatus = 2; //OCPP Status: Charging
  2938. }
  2939. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2940. {
  2941. currentStatus = 5; //OCPP Status: Finishing
  2942. }
  2943. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  2944. {
  2945. currentStatus = 4; //OCPP Status: SuspendedEV
  2946. }
  2947. 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
  2948. {
  2949. currentStatus = 7; //OCPP Status : Unavailable
  2950. }
  2951. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2952. {
  2953. currentStatus = 8; //OCPP Status: Faulted
  2954. }
  2955. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2956. {
  2957. currentStatus = 6; //OCPP Status: Reserved
  2958. }
  2959. } //end of the same index
  2960. } // end of for CCS_QUANTITY
  2961. }
  2962. else if(gunType[gun_index] == 'G')
  2963. {
  2964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2965. {
  2966. tempIndex = ((gun_index==2) ? 1: 0);
  2967. }
  2968. else
  2969. {
  2970. tempIndex = gun_index;
  2971. }
  2972. for (int index = 0; index < GB_QUANTITY; index++)
  2973. {
  2974. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2975. {
  2976. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2977. {
  2978. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2979. {
  2980. currentStatus = 1; //OCPP Status: Preparing
  2981. }
  2982. else
  2983. {
  2984. currentStatus = 0; //OCPP Status: Available
  2985. }
  2986. }
  2987. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2988. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2989. ) //S_PRECHARGE
  2990. {
  2991. currentStatus = 1; //OCPP Status: Preparing
  2992. }
  2993. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2994. {
  2995. currentStatus = 2; //OCPP Status: Charging
  2996. }
  2997. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2998. {
  2999. currentStatus = 5; //OCPP Status: Finishing
  3000. }
  3001. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3002. {
  3003. currentStatus = 4; //OCPP Status: SuspendedEV
  3004. }
  3005. 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
  3006. {
  3007. currentStatus = 7; //OCPP Status: Unavailable
  3008. }
  3009. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3010. {
  3011. currentStatus = 8; //OCPP Status: Faulted
  3012. }
  3013. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3014. {
  3015. currentStatus = 6; //OCPP Status: Reserved
  3016. }
  3017. } //end of the same index
  3018. } // end of for GB_QUANTITY
  3019. }
  3020. else
  3021. {
  3022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3023. {
  3024. tempIndex = 2;
  3025. }
  3026. else
  3027. {
  3028. tempIndex = gun_index;
  3029. }
  3030. for (int index = 0; index < AC_QUANTITY; index++)
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3033. {
  3034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3035. {
  3036. 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))
  3037. {
  3038. currentStatus = 1; //OCPP Status: Preparing
  3039. }
  3040. else
  3041. {
  3042. currentStatus = 0; //OCPP Status: Available
  3043. }
  3044. }
  3045. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3046. {
  3047. currentStatus = 1; //OCPP Status: Preparing
  3048. }
  3049. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3050. {
  3051. currentStatus = 2; //OCPP Status: Charging
  3052. }
  3053. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3054. {
  3055. currentStatus = 5; //OCPP Status: Finishing
  3056. }
  3057. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3058. {
  3059. currentStatus = 4; //OCPP Status: SuspendedEV
  3060. }
  3061. 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
  3062. {
  3063. currentStatus = 7; //OCPP Status: Unavailable
  3064. }
  3065. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3066. {
  3067. currentStatus = 8; //OCPP Status: Faulted
  3068. }
  3069. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3070. {
  3071. currentStatus = 6; //OCPP Status: Reserved
  3072. }
  3073. }//end of the same index
  3074. }//end of for AC_QUANTITY
  3075. }
  3076. //it's option
  3077. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3078. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3079. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3080. random_uuid(guid);
  3081. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3082. , MESSAGE_TYPE_CALL
  3083. , guid
  3084. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3085. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3086. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3087. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3088. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3089. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3090. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3091. LWS_Send(message);
  3092. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3093. 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*/)
  3094. {
  3095. //DEBUG_ERROR("statusNotification mapitem pass");
  3096. result = PASS;
  3097. }
  3098. return result;
  3099. }
  3100. int sendStopTransactionRequest(int gun_index)
  3101. {
  3102. mtrace();
  3103. int result = FAIL;
  3104. //char message[1500]={0};
  3105. char guid[37]={0};
  3106. char tempdata[65]={0};
  3107. int tempIndex = 0;
  3108. //int idx_sample=0;
  3109. DEBUG_ERROR("sendStopTransactionRequest \n");
  3110. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3111. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3113. if(gunType[gun_index] == 'J')
  3114. {
  3115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3116. {
  3117. tempIndex = ((gun_index==2) ? 1: 0);
  3118. }
  3119. else
  3120. {
  3121. tempIndex = gun_index;
  3122. }
  3123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3124. {
  3125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3126. {
  3127. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3128. }
  3129. }// END OF CHAdeMO_QUANTITY
  3130. }
  3131. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3132. {
  3133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3134. {
  3135. tempIndex = ((gun_index==2) ? 1: 0);
  3136. }
  3137. else
  3138. {
  3139. tempIndex = gun_index;
  3140. }
  3141. for (int index = 0; index < CCS_QUANTITY; index++)
  3142. {
  3143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3144. {
  3145. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3146. }
  3147. }// END OF CCS_QUANTITY
  3148. }
  3149. else if(gunType[gun_index] == 'G')
  3150. {
  3151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3152. {
  3153. tempIndex = ((gun_index==2) ? 1: 0);
  3154. }
  3155. else
  3156. {
  3157. tempIndex = gun_index;
  3158. }
  3159. for (int index = 0; index < GB_QUANTITY; index++)
  3160. {
  3161. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3162. {
  3163. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3164. }
  3165. }// END OF GB_QUANTITY
  3166. }
  3167. else
  3168. {
  3169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3170. {
  3171. tempIndex = 2;
  3172. }
  3173. else
  3174. {
  3175. tempIndex = gun_index;
  3176. }
  3177. for (int index = 0; index < AC_QUANTITY; index++)
  3178. {
  3179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3180. {
  3181. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3182. }
  3183. }// END OF AC_QUANTITY
  3184. }
  3185. //====================================== Stop Transaction Time =====================================================
  3186. struct timeval tmnow;
  3187. struct tm *tm;
  3188. char buf[28];//, usec_buf[6];
  3189. gettimeofday(&tmnow, NULL);
  3190. time_t t;
  3191. t = time(NULL);
  3192. /*UTC time and date*/
  3193. tm = gmtime(&t);
  3194. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3196. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3197. random_uuid(guid);
  3198. /***********************************transactionData******************************************************/
  3199. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3201. //=================================
  3202. // Transaction_Begin
  3203. //=================================
  3204. //============================================ Energy.Active.Import.Interval ================================
  3205. //idx_sample=0;
  3206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3209. 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*/]);
  3210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3211. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3212. {
  3213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3214. }
  3215. else
  3216. {
  3217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3218. }
  3219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3221. //=================================
  3222. // Transaction_End
  3223. //=================================
  3224. // ================================= Current.Import L1 ===============================================
  3225. //idx_sample=1;
  3226. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3227. if(gunType[gun_index] == 'J')
  3228. {
  3229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3230. {
  3231. tempIndex = ((gun_index==2) ? 1: 0);
  3232. }
  3233. else
  3234. {
  3235. tempIndex = gun_index;
  3236. }
  3237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3238. {
  3239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3240. {
  3241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3242. }
  3243. }// End of for CHAdeMO_QUANTITY
  3244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3245. }
  3246. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3247. {
  3248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3249. {
  3250. tempIndex = ((gun_index==2) ? 1: 0);
  3251. }
  3252. else
  3253. {
  3254. tempIndex = gun_index;
  3255. }
  3256. for (int index = 0; index < CCS_QUANTITY; index++)
  3257. {
  3258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3259. {
  3260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3261. }
  3262. }// End of for CCS_QUANTITY
  3263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3264. }
  3265. else if(gunType[gun_index] == 'G')
  3266. {
  3267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3268. {
  3269. tempIndex = ((gun_index==2) ? 1: 0);
  3270. }
  3271. else
  3272. {
  3273. tempIndex = gun_index;
  3274. }
  3275. for (int index = 0; index < GB_QUANTITY; index++)
  3276. {
  3277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3278. {
  3279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3280. }
  3281. }// End of for GB_QUANTITY
  3282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3283. }
  3284. else
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3287. {
  3288. tempIndex = 2;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = gun_index;
  3293. }
  3294. for (int index = 0; index < AC_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3297. {
  3298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3299. }
  3300. }// End of for AC_QUANTITY
  3301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3302. }
  3303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3308. // ================================= Energy.Active.Import.Interval ==============================================
  3309. //idx_sample=2;
  3310. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3311. if(gunType[gun_index] == 'J')
  3312. {
  3313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3314. {
  3315. tempIndex = ((gun_index==2) ? 1: 0);
  3316. }
  3317. else
  3318. {
  3319. tempIndex = gun_index;
  3320. }
  3321. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3322. {
  3323. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3324. {
  3325. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3326. }
  3327. }// END OF CHAdeMO_QUANTITY
  3328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3329. }
  3330. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3331. {
  3332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3333. {
  3334. tempIndex = ((gun_index==2) ? 1: 0);
  3335. }
  3336. else
  3337. {
  3338. tempIndex = gun_index;
  3339. }
  3340. for (int index = 0; index < CCS_QUANTITY; index++)
  3341. {
  3342. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3343. {
  3344. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3345. }
  3346. }// END OF CCS_QUANTITY
  3347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3348. }
  3349. else if(gunType[gun_index] == 'G')
  3350. {
  3351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3352. {
  3353. tempIndex = ((gun_index==2) ? 1: 0);
  3354. }
  3355. else
  3356. {
  3357. tempIndex = gun_index;
  3358. }
  3359. for (int index = 0; index < GB_QUANTITY; index++)
  3360. {
  3361. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3362. {
  3363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3364. }
  3365. }// END OF GB_QUANTITY
  3366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3367. }
  3368. else
  3369. {
  3370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3371. {
  3372. tempIndex = 2;
  3373. }
  3374. else
  3375. {
  3376. tempIndex = gun_index;
  3377. }
  3378. for (int index = 0; index < AC_QUANTITY; index++)
  3379. {
  3380. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3381. {
  3382. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3383. }
  3384. }// END OF AC_QUANTITY
  3385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3386. }
  3387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3392. //=================================== Power.Active.Import ==================================================
  3393. //idx_sample=3;
  3394. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3395. if(gunType[gun_index] == 'J')
  3396. {
  3397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3398. {
  3399. tempIndex = ((gun_index==2) ? 1: 0);
  3400. }
  3401. else
  3402. {
  3403. tempIndex = gun_index;
  3404. }
  3405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3406. {
  3407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3408. {
  3409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3410. }
  3411. } // End for CHAdeMO_QUANTITY
  3412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3413. }
  3414. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3415. {
  3416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3417. {
  3418. tempIndex = ((gun_index==2) ? 1: 0);
  3419. }
  3420. else
  3421. {
  3422. tempIndex = gun_index;
  3423. }
  3424. for (int index = 0; index < CCS_QUANTITY; index++)
  3425. {
  3426. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3427. {
  3428. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3429. }
  3430. } // END for CCS_QUANTITY
  3431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3432. }
  3433. else if(gunType[gun_index] == 'G')
  3434. {
  3435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3436. {
  3437. tempIndex = ((gun_index==2) ? 1: 0);
  3438. }
  3439. else
  3440. {
  3441. tempIndex = gun_index;
  3442. }
  3443. for (int index = 0; index < GB_QUANTITY; index++)
  3444. {
  3445. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3446. {
  3447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3448. }
  3449. }// END for GB_QUANTITY
  3450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3451. }
  3452. else
  3453. {
  3454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3455. {
  3456. tempIndex = 2;
  3457. }
  3458. else
  3459. {
  3460. tempIndex = gun_index;
  3461. }
  3462. for (int index = 0; index < AC_QUANTITY; index++)
  3463. {
  3464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3465. {
  3466. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3467. }
  3468. } // END for AC_QUANTITY
  3469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3470. }
  3471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3476. //============================ Voltage L1 ====================================
  3477. //idx_sample=4;
  3478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3479. if(gunType[gun_index] == 'J')
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3482. {
  3483. tempIndex = ((gun_index==2) ? 1: 0);
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3492. {
  3493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3494. }
  3495. } // END OF FOR CHAdeMO_QUANTITY
  3496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3497. }
  3498. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3499. {
  3500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3501. {
  3502. tempIndex = ((gun_index==2) ? 1: 0);
  3503. }
  3504. else
  3505. {
  3506. tempIndex = gun_index;
  3507. }
  3508. for (int index = 0; index < CCS_QUANTITY; index++)
  3509. {
  3510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3511. {
  3512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3513. }
  3514. } // END OF FOR CCS_QUANTITY
  3515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3516. }
  3517. else if(gunType[gun_index] == 'G')
  3518. {
  3519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3520. {
  3521. tempIndex = ((gun_index==2) ? 1: 0);
  3522. }
  3523. else
  3524. {
  3525. tempIndex = gun_index;
  3526. }
  3527. for (int index = 0; index < GB_QUANTITY; index++)
  3528. {
  3529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3530. {
  3531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3532. }
  3533. } // END OF FOR GB_QUANTITY
  3534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3535. }
  3536. else
  3537. {
  3538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3539. {
  3540. tempIndex = 2;
  3541. }
  3542. else
  3543. {
  3544. tempIndex = gun_index;
  3545. }
  3546. for (int index = 0; index < AC_QUANTITY; index++)
  3547. {
  3548. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3549. {
  3550. 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
  3551. }
  3552. } // END OF FOR AC_QUANTITY
  3553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3554. }
  3555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3560. //====================== SoC ================================
  3561. //idx_sample=5;
  3562. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3563. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3564. {
  3565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3566. {
  3567. tempIndex = ((gun_index==2) ? 1: 0);
  3568. }
  3569. else
  3570. {
  3571. tempIndex = gun_index;
  3572. }
  3573. if(gunType[gun_index] == 'J')
  3574. {
  3575. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3576. {
  3577. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3578. {
  3579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3580. }
  3581. }
  3582. }
  3583. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3584. {
  3585. for (int index = 0; index < CCS_QUANTITY; index++)
  3586. {
  3587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3588. {
  3589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3590. }
  3591. }
  3592. }
  3593. else if(gunType[gun_index] == 'G')
  3594. {
  3595. for (int index = 0; index < GB_QUANTITY; index++)
  3596. {
  3597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3598. {
  3599. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3600. }
  3601. }
  3602. }
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3609. } // END FOR DC CASE
  3610. // ================================= Current.Import L2 ===============================================
  3611. //idx_sample=6;
  3612. // AC 3 phse L2 current
  3613. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3614. {
  3615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3616. {
  3617. tempIndex = 2;
  3618. }
  3619. else
  3620. {
  3621. tempIndex = gun_index;
  3622. }
  3623. for (int index = 0; index < AC_QUANTITY; index++)
  3624. {
  3625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3626. {
  3627. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3628. }
  3629. }// End of for AC_QUANTITY
  3630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3631. }
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3637. // ================================= Current.Import L3 ===============================================
  3638. //idx_sample=7;
  3639. // AC 3 phse L3 current
  3640. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3641. {
  3642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3643. {
  3644. tempIndex = 2;
  3645. }
  3646. else
  3647. {
  3648. tempIndex = gun_index;
  3649. }
  3650. for (int index = 0; index < AC_QUANTITY; index++)
  3651. {
  3652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3653. {
  3654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3655. }
  3656. }// End of for AC_QUANTITY
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3658. }
  3659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3664. //============================ Voltage L2 ====================================
  3665. //idx_sample=8;
  3666. // AC 3 phse L2 voltage
  3667. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3668. {
  3669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3670. {
  3671. tempIndex = 2;
  3672. }
  3673. else
  3674. {
  3675. tempIndex = gun_index;
  3676. }
  3677. for (int index = 0; index < AC_QUANTITY; index++)
  3678. {
  3679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3680. {
  3681. 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
  3682. }
  3683. } // END OF FOR AC_QUANTITY
  3684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3685. }
  3686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3691. //============================ Voltage L3 ====================================
  3692. //idx_sample=8;
  3693. // AC 3 phse L3 voltage
  3694. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3695. {
  3696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3697. {
  3698. tempIndex = 2;
  3699. }
  3700. else
  3701. {
  3702. tempIndex = gun_index;
  3703. }
  3704. for (int index = 0; index < AC_QUANTITY; index++)
  3705. {
  3706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3707. {
  3708. 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
  3709. }
  3710. } // END OF FOR AC_QUANTITY
  3711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3712. }
  3713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3718. //================================================ Message create ====================================================
  3719. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3720. {
  3721. 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\"}]}]}]"
  3722. ,gun_index+1
  3723. ,MESSAGE_TYPE_CALL
  3724. ,guid
  3725. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3726. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3727. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3728. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3729. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3730. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3773. );
  3774. }
  3775. else
  3776. {
  3777. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3778. {
  3779. 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\"}]}]}]"
  3780. ,gun_index+1
  3781. ,MESSAGE_TYPE_CALL
  3782. ,guid
  3783. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3784. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3785. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3787. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3788. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3824. );
  3825. }
  3826. else
  3827. {
  3828. 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\"}]}]}]"
  3829. ,gun_index+1
  3830. ,MESSAGE_TYPE_CALL
  3831. ,guid
  3832. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3833. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3834. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3836. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3837. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  3901. );
  3902. }
  3903. }
  3904. #if 1 // for TempStopTransaction
  3905. //Delete TempStopTransaction
  3906. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3907. {
  3908. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3909. }
  3910. #endif
  3911. #if 1
  3912. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3913. if(hashmap_operation(0, guid, tempdata) == 1)
  3914. {
  3915. result = PASS;
  3916. DEBUG_INFO("StopTransaction mapitem pass\n");
  3917. }
  3918. #endif
  3919. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3920. /*
  3921. if(GetTransactionQueueNum() == 1)
  3922. {
  3923. LWS_Send(queuedata+2);
  3924. }*/
  3925. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3926. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  3927. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  3928. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3929. {
  3930. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3931. }
  3932. //for test
  3933. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3934. return result;
  3935. }
  3936. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  3937. {
  3938. mtrace();
  3939. int result = FAIL;
  3940. char guid[37]={0};
  3941. char tempdata[65]={0};
  3942. int tempIndex = 0;
  3943. DEBUG_INFO("sendMeterValuesRequest ...\n");
  3944. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  3945. /*
  3946. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3947. {
  3948. DEBUG_INFO("NOT SENT METER Vlaue\n");
  3949. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  3950. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  3951. return result;
  3952. }*/
  3953. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  3954. {
  3955. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3956. }
  3957. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3958. //set value
  3959. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  3960. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  3961. random_uuid(guid);
  3962. //UTC Date time
  3963. struct timeval tmnow;
  3964. struct tm *tm;
  3965. char buf[28];//, usec_buf[6];
  3966. gettimeofday(&tmnow, NULL);
  3967. time_t t;
  3968. t = time(NULL);
  3969. /*UTC time and date*/
  3970. tm = gmtime(&t);
  3971. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3972. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  3973. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3974. //idx_sample=0;
  3975. //********************************(1)Current.Import L1************************************************/
  3976. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3977. if(gunType[gun_index] == 'J')
  3978. {
  3979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3980. {
  3981. tempIndex = ((gun_index==2) ? 1: 0);
  3982. }
  3983. else
  3984. {
  3985. tempIndex = gun_index;
  3986. }
  3987. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3988. {
  3989. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3990. {
  3991. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  3992. }
  3993. }
  3994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  3995. }
  3996. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3997. {
  3998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3999. {
  4000. tempIndex = ((gun_index==2) ? 1: 0);
  4001. }
  4002. else
  4003. {
  4004. tempIndex = gun_index;
  4005. }
  4006. for (int index = 0; index < CCS_QUANTITY; index++)
  4007. {
  4008. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4009. {
  4010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4011. }
  4012. }
  4013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4014. }
  4015. else if(gunType[gun_index] == 'G')
  4016. {
  4017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4018. {
  4019. tempIndex = ((gun_index==2) ? 1: 0);
  4020. }
  4021. else
  4022. {
  4023. tempIndex = gun_index;
  4024. }
  4025. for (int index = 0; index < GB_QUANTITY; index++)
  4026. {
  4027. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4028. {
  4029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4030. }
  4031. }
  4032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4033. }
  4034. else
  4035. {
  4036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4037. {
  4038. tempIndex = 2;
  4039. }
  4040. else
  4041. {
  4042. tempIndex = gun_index;
  4043. }
  4044. for (int index = 0; index < AC_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4047. {
  4048. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4049. }
  4050. }
  4051. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4052. }
  4053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4057. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4058. //idx_sample=1;
  4059. //********************************(2)Energy.Active.Import.Register ************************************************/
  4060. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4061. if(gunType[gun_index] == 'J')
  4062. {
  4063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4064. {
  4065. tempIndex = ((gun_index==2) ? 1: 0);
  4066. }
  4067. else
  4068. {
  4069. tempIndex = gun_index;
  4070. }
  4071. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4072. {
  4073. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4074. {
  4075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4076. }
  4077. }
  4078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4079. }
  4080. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4081. {
  4082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4083. {
  4084. tempIndex = ((gun_index==2) ? 1: 0);
  4085. }
  4086. else
  4087. {
  4088. tempIndex = gun_index;
  4089. }
  4090. for (int index = 0; index < CCS_QUANTITY; index++)
  4091. {
  4092. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4093. {
  4094. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4095. }
  4096. }
  4097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4098. }
  4099. else if(gunType[gun_index] == 'G')
  4100. {
  4101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4102. {
  4103. tempIndex = ((gun_index==2) ? 1: 0);
  4104. }
  4105. else
  4106. {
  4107. tempIndex = gun_index;
  4108. }
  4109. for (int index = 0; index < GB_QUANTITY; index++)
  4110. {
  4111. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4112. {
  4113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4114. }
  4115. }
  4116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4117. }
  4118. else
  4119. {
  4120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4121. {
  4122. tempIndex = 2;
  4123. }
  4124. else
  4125. {
  4126. tempIndex = gun_index;
  4127. }
  4128. for (int index = 0; index < AC_QUANTITY; index++)
  4129. {
  4130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4131. {
  4132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4133. }
  4134. }
  4135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4136. }
  4137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4142. //idx_sample=2;
  4143. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4144. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4145. if(gunType[gun_index] == 'J')
  4146. {
  4147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4148. {
  4149. tempIndex = ((gun_index==2) ? 1: 0);
  4150. }
  4151. else
  4152. {
  4153. tempIndex = gun_index;
  4154. }
  4155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4156. {
  4157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4158. {
  4159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4160. }
  4161. } // END OF FOR CHAdeMO_QUANTITY
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4163. }
  4164. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4165. {
  4166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4167. {
  4168. tempIndex = ((gun_index==2) ? 1: 0);
  4169. }
  4170. else
  4171. {
  4172. tempIndex = gun_index;
  4173. }
  4174. for (int index = 0; index < CCS_QUANTITY; index++)
  4175. {
  4176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4177. {
  4178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4179. }
  4180. } // END OF CCS_QUANTITY
  4181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4182. }
  4183. else if(gunType[gun_index] == 'G')
  4184. {
  4185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4186. {
  4187. tempIndex = ((gun_index==2) ? 1: 0);
  4188. }
  4189. else
  4190. {
  4191. tempIndex = gun_index;
  4192. }
  4193. for (int index = 0; index < GB_QUANTITY; index++)
  4194. {
  4195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4196. {
  4197. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4198. }
  4199. } // END OF GB_QUANTITY
  4200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4201. }
  4202. else
  4203. {
  4204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4205. {
  4206. tempIndex = 2;
  4207. }
  4208. else
  4209. {
  4210. tempIndex = gun_index;
  4211. }
  4212. for (int index = 0; index < AC_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4215. {
  4216. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4217. }
  4218. }
  4219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4220. }
  4221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4226. //idx_sample=3;
  4227. //********************************(4)Power.Active.Import************************************************/
  4228. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4229. if(gunType[gun_index] == 'J')
  4230. {
  4231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4232. {
  4233. tempIndex = ((gun_index==2) ? 1: 0);
  4234. }
  4235. else
  4236. {
  4237. tempIndex = gun_index;
  4238. }
  4239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4242. {
  4243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4244. }
  4245. } // END OF FOR
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4247. }
  4248. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4249. {
  4250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4251. {
  4252. tempIndex = ((gun_index==2) ? 1: 0);
  4253. }
  4254. else
  4255. {
  4256. tempIndex = gun_index;
  4257. }
  4258. for (int index = 0; index < CCS_QUANTITY; index++)
  4259. {
  4260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4261. {
  4262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4263. }
  4264. }
  4265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4266. }
  4267. else if(gunType[gun_index] == 'G')
  4268. {
  4269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4270. {
  4271. tempIndex = ((gun_index==2) ? 1: 0);
  4272. }
  4273. else
  4274. {
  4275. tempIndex = gun_index;
  4276. }
  4277. for (int index = 0; index < GB_QUANTITY; index++)
  4278. {
  4279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4280. {
  4281. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4282. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4283. }
  4284. }
  4285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4286. }
  4287. else
  4288. {
  4289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4290. {
  4291. tempIndex = 2;
  4292. }
  4293. else
  4294. {
  4295. tempIndex = gun_index;
  4296. }
  4297. for (int index = 0; index < AC_QUANTITY; index++)
  4298. {
  4299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4300. {
  4301. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4302. }
  4303. }
  4304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4305. }
  4306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4311. //idx_sample=4;
  4312. //***********************************************(5)VOLTAGE L1******************************************************/
  4313. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4314. if(gunType[gun_index] == 'J')
  4315. {
  4316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4317. {
  4318. tempIndex = ((gun_index==2) ? 1: 0);
  4319. }
  4320. else
  4321. {
  4322. tempIndex = gun_index;
  4323. }
  4324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4325. {
  4326. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4327. {
  4328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4329. }
  4330. }
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4332. }
  4333. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4334. {
  4335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4336. {
  4337. tempIndex = ((gun_index==2) ? 1: 0);
  4338. }
  4339. else
  4340. {
  4341. tempIndex = gun_index;
  4342. }
  4343. for (int index = 0; index < CCS_QUANTITY; index++)
  4344. {
  4345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4346. {
  4347. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4348. }
  4349. }
  4350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4351. }
  4352. else if(gunType[gun_index] == 'G')
  4353. {
  4354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4355. {
  4356. tempIndex = ((gun_index==2) ? 1: 0);
  4357. }
  4358. else
  4359. {
  4360. tempIndex = gun_index;
  4361. }
  4362. for (int index = 0; index < GB_QUANTITY; index++)
  4363. {
  4364. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4365. {
  4366. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4367. }
  4368. }
  4369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4370. }
  4371. else
  4372. {
  4373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4374. {
  4375. tempIndex = 2;
  4376. }
  4377. else
  4378. {
  4379. tempIndex = gun_index;
  4380. }
  4381. for (int index = 0; index < AC_QUANTITY; index++)
  4382. {
  4383. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4384. {
  4385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4386. }
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4389. }
  4390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4395. //***********************************************(6)SOC******************************************************/
  4396. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4397. {
  4398. //idx_sample=5;
  4399. //sampledValue = NULL;
  4400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4401. {
  4402. tempIndex = ((gun_index==2) ? 1: 0);
  4403. }
  4404. else
  4405. {
  4406. tempIndex = gun_index;
  4407. }
  4408. if(gunType[gun_index] == 'J')
  4409. {
  4410. //tempIndex = ((gun_index==2) ? 1: 0);
  4411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4412. {
  4413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4414. {
  4415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4416. }
  4417. }
  4418. }
  4419. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4420. {
  4421. //tempIndex = ((gun_index==2) ? 1: 0);
  4422. for (int index = 0; index < CCS_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4425. {
  4426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4427. }
  4428. }
  4429. }
  4430. else if(gunType[gun_index] == 'G')
  4431. {
  4432. //tempIndex = ((gun_index==2) ? 1: 0);
  4433. for (int index = 0; index < GB_QUANTITY; index++)
  4434. {
  4435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4436. {
  4437. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4438. }
  4439. }
  4440. }
  4441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4447. }
  4448. //********************************(7)Current.Import L2************************************************/
  4449. // Only for AC 3 phase
  4450. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4451. {
  4452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4453. {
  4454. tempIndex = 2;
  4455. }
  4456. else
  4457. {
  4458. tempIndex = gun_index;
  4459. }
  4460. for (int index = 0; index < AC_QUANTITY; index++)
  4461. {
  4462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4463. {
  4464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4465. }
  4466. }
  4467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4468. }
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4474. //********************************(8)Current.Import L3************************************************/
  4475. // Only for AC 3 phase
  4476. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4479. {
  4480. tempIndex = 2;
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < AC_QUANTITY; index++)
  4487. {
  4488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4489. {
  4490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4491. }
  4492. }
  4493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4494. }
  4495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4500. //***********************************************(9)VOLTAGE L2******************************************************/
  4501. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4502. {
  4503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4504. {
  4505. tempIndex = 2;
  4506. }
  4507. else
  4508. {
  4509. tempIndex = gun_index;
  4510. }
  4511. for (int index = 0; index < AC_QUANTITY; index++)
  4512. {
  4513. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4514. {
  4515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4516. }
  4517. }
  4518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4525. //***********************************************(10)VOLTAGE L3******************************************************/
  4526. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4527. {
  4528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4529. {
  4530. tempIndex = 2;
  4531. }
  4532. else
  4533. {
  4534. tempIndex = gun_index;
  4535. }
  4536. for (int index = 0; index < AC_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4539. {
  4540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4541. }
  4542. }
  4543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4544. }
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4550. // Message create ====================================================================================================
  4551. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4552. {
  4553. 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\"}]}]}]"
  4554. ,gun_index + 1
  4555. ,MESSAGE_TYPE_CALL
  4556. ,guid
  4557. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4558. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4559. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4560. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4561. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4562. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4563. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4564. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4602. );
  4603. }
  4604. else
  4605. {
  4606. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4607. {
  4608. 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\"}]}]}]"
  4609. ,gun_index + 1
  4610. ,MESSAGE_TYPE_CALL
  4611. ,guid
  4612. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4613. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4614. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4615. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4650. );
  4651. }
  4652. else
  4653. {
  4654. 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\"}]}]}]"
  4655. ,gun_index + 1
  4656. ,MESSAGE_TYPE_CALL
  4657. ,guid
  4658. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4659. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4660. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4724. );
  4725. }
  4726. }
  4727. // Put request guid to hash map
  4728. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4729. 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*/)
  4730. {
  4731. result = PASS;
  4732. DEBUG_INFO("MeterValues mapitem pass\n");
  4733. }
  4734. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4735. /*
  4736. if(GetTransactionQueueNum() == 1)
  4737. {
  4738. LWS_Send(queuedata +2);
  4739. }*/
  4740. return result;
  4741. }
  4742. //==========================================
  4743. // send confirm routine
  4744. //==========================================
  4745. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4746. {
  4747. mtrace();
  4748. int result = FAIL;
  4749. char message[100]={0};
  4750. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4752. LWS_Send(message);
  4753. result = TRUE;
  4754. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4755. return result;
  4756. }
  4757. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4758. {
  4759. mtrace();
  4760. int result = FAIL;
  4761. char message[100]={0};
  4762. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4763. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4764. LWS_Send(message);
  4765. result = TRUE;
  4766. return result;
  4767. }
  4768. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4769. {
  4770. mtrace();
  4771. int result = FAIL;
  4772. char message[100]={0};
  4773. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4774. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4775. LWS_Send(message);
  4776. result = TRUE;
  4777. return result;
  4778. }
  4779. int sendClearCacheConfirmation(char *uuid,char *payload)
  4780. {
  4781. mtrace();
  4782. int result = FAIL;
  4783. char message[500]={0};
  4784. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4785. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4786. LWS_Send(message);
  4787. return result;
  4788. }
  4789. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4790. {
  4791. mtrace();
  4792. int result = FAIL;
  4793. char message[500]={0};
  4794. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4795. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4796. LWS_Send(message);
  4797. return result;
  4798. }
  4799. int sendDataTransferConfirmation(char *uuid,char *payload)
  4800. {
  4801. mtrace();
  4802. char statusStr[20]={0};
  4803. char dataStr[10]={0};
  4804. char sstr[20]={0};
  4805. int c = 0;
  4806. char *loc;
  4807. int result = FAIL;
  4808. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4809. /**********************status**************************/
  4810. loc = strstr(payload, "status");
  4811. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4812. c = 0;
  4813. while (loc[3+strlen("status")+c] != '\"')
  4814. {
  4815. sstr[c] = loc[3+strlen("status")+c];
  4816. c++;
  4817. }
  4818. sstr[c] = '\0';
  4819. strcpy(statusStr, sstr);
  4820. /**********************data**************************/
  4821. loc = strstr(payload, "data");
  4822. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4823. c = 0;
  4824. while (loc[3+strlen("data")+c] != '\"')
  4825. {
  4826. sstr[c] = loc[3+strlen("data")+c];
  4827. c++;
  4828. }
  4829. sstr[c] = '\0';
  4830. strcpy(dataStr, sstr);
  4831. return result;
  4832. }
  4833. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4834. {
  4835. mtrace();
  4836. int result = FAIL;
  4837. char message[1000]={0};
  4838. int CompositeScheduleIndex = 0;
  4839. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4840. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4841. if(nPeriod == 0)
  4842. {
  4843. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4844. {
  4845. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4846. ,MESSAGE_TYPE_CALLRESULT
  4847. ,uuid
  4848. ,payload
  4849. ,connectorIdInt);
  4850. }
  4851. else
  4852. {
  4853. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4854. ,MESSAGE_TYPE_CALLRESULT
  4855. ,uuid
  4856. ,payload
  4857. ,connectorIdInt
  4858. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4859. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4860. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4861. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4862. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4863. }
  4864. }
  4865. else
  4866. {
  4867. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4868. ,MESSAGE_TYPE_CALLRESULT
  4869. ,uuid
  4870. ,payload
  4871. ,connectorIdInt
  4872. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4873. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4874. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4875. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4876. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4877. {
  4878. if (idx_sample == 0)
  4879. {
  4880. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4881. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4882. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4883. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4884. }
  4885. else
  4886. {
  4887. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4888. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4889. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4890. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4891. }
  4892. }
  4893. sprintf(message + strlen(message), "]}}]");
  4894. }
  4895. LWS_Send(message);
  4896. result = TRUE;
  4897. return result;
  4898. }
  4899. int sendGetConfigurationConfirmation(char *uuid)
  4900. {
  4901. mtrace();
  4902. int result = FAIL;
  4903. int MaxKeySupported = 0;
  4904. int sentConfigurationNumber= 0;
  4905. int sentunConfigurationNumber= 0;
  4906. char message[4000]={0};
  4907. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4908. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4909. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4910. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4911. ,MESSAGE_TYPE_CALLRESULT
  4912. ,uuid );
  4913. //configuration key
  4914. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4915. {
  4916. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4917. {
  4918. if (sentConfigurationNumber == 0)
  4919. {
  4920. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4921. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4922. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4923. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4924. }
  4925. else
  4926. {
  4927. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4928. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4929. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4930. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4931. }
  4932. sentConfigurationNumber = sentConfigurationNumber + 1;
  4933. }
  4934. }
  4935. sprintf(message + strlen(message), "]");
  4936. if(UnknownKeynum != 0)
  4937. {
  4938. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4939. //unkown key
  4940. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4941. {
  4942. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4943. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4944. if(sentunConfigurationNumber == 0)
  4945. {
  4946. sprintf(message + strlen(message), "\"%s\""
  4947. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4948. }
  4949. else
  4950. {
  4951. sprintf(message + strlen(message), ",\"%s\""
  4952. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4953. }
  4954. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4955. }
  4956. sprintf(message + strlen(message), "]");
  4957. }
  4958. sprintf(message + strlen(message), "}]");
  4959. LWS_Send(message);
  4960. return result;
  4961. }
  4962. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4963. {
  4964. mtrace();
  4965. int result = FAIL;
  4966. char message[400]={0};
  4967. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4968. if(strcmp(payload,"")==0)
  4969. {
  4970. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4971. }
  4972. else
  4973. {
  4974. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4975. }
  4976. LWS_Send(message);
  4977. result = TRUE;
  4978. return result;
  4979. }
  4980. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4981. {
  4982. mtrace();
  4983. int result = FAIL;
  4984. char message[80]={0};
  4985. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4986. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4987. LWS_Send(message);
  4988. result = TRUE;
  4989. return result;
  4990. }
  4991. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4992. {
  4993. mtrace();
  4994. int result = FAIL;
  4995. char message[80]={0};
  4996. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4997. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4998. LWS_Send(message);
  4999. result = TRUE;
  5000. return result;
  5001. }
  5002. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5003. {
  5004. mtrace();
  5005. int result = FAIL;
  5006. char message[80]={0};
  5007. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5008. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5009. LWS_Send(message);
  5010. result = TRUE;
  5011. return result;
  5012. }
  5013. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5014. {
  5015. mtrace();
  5016. int result = FAIL;
  5017. char message[80]={0};
  5018. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5019. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5020. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5021. LWS_Send(message);
  5022. result = TRUE;
  5023. return result;
  5024. }
  5025. int sendResetConfirmation(char *uuid,char *payload)
  5026. {
  5027. mtrace();
  5028. int result = FAIL;
  5029. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5030. char message[80]={0};
  5031. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5032. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5033. LWS_Send(message);
  5034. result = TRUE;
  5035. return result;
  5036. }
  5037. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5038. {
  5039. mtrace();
  5040. int result = FAIL;
  5041. char message[500]={0};
  5042. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5043. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5044. LWS_Send(message);
  5045. result = TRUE;
  5046. return result;
  5047. }
  5048. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5049. {
  5050. mtrace();
  5051. int result = FAIL;
  5052. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5053. char message[80]={0};
  5054. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5055. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5056. LWS_Send(message);
  5057. result = TRUE;
  5058. return result;
  5059. }
  5060. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5061. {
  5062. mtrace();
  5063. int result = FAIL;
  5064. char message[80]={0};
  5065. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5066. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5067. LWS_Send(message);
  5068. result = TRUE;
  5069. return result;
  5070. }
  5071. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5072. {
  5073. mtrace();
  5074. int result = FAIL;
  5075. char message[80]={0};
  5076. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5077. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5078. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5079. LWS_Send(message);
  5080. result = TRUE;
  5081. return result;
  5082. }
  5083. int sendUpdateFirmwareConfirmation(char *uuid)
  5084. {
  5085. mtrace();
  5086. int result = FAIL;
  5087. char message[60]={0};
  5088. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5089. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5090. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5091. LWS_Send(message);
  5092. result = TRUE;
  5093. return result;
  5094. }
  5095. //==========================================
  5096. // send CallError routine
  5097. //==========================================
  5098. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5099. {
  5100. mtrace();
  5101. char message[220]={0};
  5102. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5103. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5104. LWS_Send(message);
  5105. }
  5106. //==========================================
  5107. // Handle server request routine Start
  5108. //==========================================
  5109. int handleCancelReservationRequest(char *uuid, char *payload)
  5110. {
  5111. mtrace();
  5112. int result = FAIL;
  5113. int gunNO = 0;
  5114. int reservationIdInt =0;
  5115. char comfirmstr[20];
  5116. DEBUG_INFO("handleCancelReservationRequest...\n");
  5117. json_object *CancelReservation;
  5118. CancelReservation = json_tokener_parse(payload);
  5119. if(!is_error(CancelReservation))
  5120. {
  5121. // Required data
  5122. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5123. }
  5124. json_object_put(CancelReservation);
  5125. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5126. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5127. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5128. //check Transaction active
  5129. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5131. {
  5132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5133. {
  5134. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5135. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5136. if(gunType[2] == 'J')
  5137. {
  5138. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5139. }
  5140. else
  5141. {
  5142. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5143. }
  5144. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5145. goto end;
  5146. }
  5147. }
  5148. for (int index = 0; index < CCS_QUANTITY; index++)
  5149. {
  5150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5151. {
  5152. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5153. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5154. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5155. {
  5156. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5157. }
  5158. else
  5159. {
  5160. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5161. }
  5162. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5163. goto end;
  5164. }
  5165. }
  5166. for (int index = 0; index < GB_QUANTITY; index++)
  5167. {
  5168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5169. {
  5170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5171. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5172. if(gunType[2] == 'G')
  5173. {
  5174. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5175. }
  5176. else
  5177. {
  5178. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5179. }
  5180. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5181. goto end;
  5182. }
  5183. }
  5184. for (int index = 0; index < AC_QUANTITY; index++)
  5185. {
  5186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5187. {
  5188. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5189. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5191. {
  5192. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5193. }
  5194. else
  5195. {
  5196. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5197. }
  5198. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5199. goto end;
  5200. }
  5201. }
  5202. //The reservationId does NOT match the reservationId
  5203. sendCancelReservationConfirmation(uuid, comfirmstr);
  5204. end:
  5205. // Fill in ocpp packet uuid
  5206. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5207. return result;
  5208. }
  5209. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5210. {
  5211. mtrace();
  5212. int result = FAIL;
  5213. int gunIndex = 0;
  5214. char typeStr[16]={0};
  5215. char comfirmstr[20];
  5216. int specificId = FALSE;
  5217. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5218. json_object *ChangeAvailability;
  5219. ChangeAvailability = json_tokener_parse(payload);
  5220. if(!is_error(ChangeAvailability))
  5221. {
  5222. // Required data
  5223. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5224. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5225. }
  5226. json_object_put(ChangeAvailability);
  5227. if(gunIndex != 0)
  5228. {
  5229. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5230. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5231. }
  5232. else
  5233. {
  5234. for(int i=0; i < gunTotalNumber; i++)
  5235. {
  5236. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5237. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5238. }
  5239. }
  5240. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5242. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5243. {
  5244. specificId = TRUE;
  5245. }
  5246. if(specificId == FALSE)
  5247. goto end;
  5248. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5249. {
  5250. //----------------------gunIndex is 0 ------------------------------------------------//
  5251. if(gunIndex == 0)
  5252. {
  5253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5254. {
  5255. for(int i=0; i < gunTotalNumber; i++)
  5256. {
  5257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5258. {
  5259. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5260. {
  5261. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5262. {
  5263. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5264. goto end;
  5265. }
  5266. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5267. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5270. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5271. {
  5272. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5273. goto end;
  5274. }
  5275. }
  5276. }//END FOR CHAdeMO_QUANTITY
  5277. for (int index = 0; index < CCS_QUANTITY; index++)
  5278. {
  5279. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5280. {
  5281. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5282. {
  5283. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5284. goto end;
  5285. }
  5286. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5287. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5288. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5289. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5290. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5291. {
  5292. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5293. goto end;
  5294. }
  5295. }
  5296. }//END FOR CCS_QUANTITY
  5297. for (int index = 0; index < GB_QUANTITY; index++)
  5298. {
  5299. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5300. {
  5301. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5302. {
  5303. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5304. goto end;
  5305. }
  5306. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5307. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5308. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5310. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5311. {
  5312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5313. goto end;
  5314. }
  5315. }
  5316. }// END FOR GB_QUANTITY
  5317. for (int index = 0; index < AC_QUANTITY; index++)
  5318. {
  5319. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5320. {
  5321. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5322. {
  5323. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5324. goto end;
  5325. }
  5326. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5327. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5328. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5329. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5330. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5331. {
  5332. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5333. goto end;
  5334. }
  5335. }
  5336. }//END FOR AC_QUANTITY
  5337. }// END FOR gunTotalNumber
  5338. }
  5339. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5340. {
  5341. for(int i=0; i < gunTotalNumber; i++)
  5342. {
  5343. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5344. {
  5345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5346. goto end;
  5347. }
  5348. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5349. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5350. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5351. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5352. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5353. {
  5354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5355. goto end;
  5356. }
  5357. }
  5358. }
  5359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5360. goto end;
  5361. }
  5362. //----------------------gunIndex is not 0 ------------------------------------------------//
  5363. //check Transaction active
  5364. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5365. {
  5366. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5367. {
  5368. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5369. {
  5370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5371. goto end;
  5372. }
  5373. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5374. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5378. {
  5379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5380. goto end;
  5381. }
  5382. else
  5383. {
  5384. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5385. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5386. goto end;
  5387. }
  5388. }
  5389. }//END FOR CHAdeMO_QUANTITY
  5390. for (int index = 0; index < CCS_QUANTITY; index++)
  5391. {
  5392. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5393. {
  5394. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5395. {
  5396. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5397. goto end;
  5398. }
  5399. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5400. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5401. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5402. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5403. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5404. {
  5405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5406. goto end;
  5407. }
  5408. else
  5409. {
  5410. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5412. goto end;
  5413. }
  5414. }
  5415. }//END FOR CCS_QUANTITY
  5416. for (int index = 0; index < GB_QUANTITY; index++)
  5417. {
  5418. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5419. {
  5420. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5421. {
  5422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5423. goto end;
  5424. }
  5425. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5426. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5427. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5430. {
  5431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5432. goto end;
  5433. }
  5434. else
  5435. {
  5436. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5438. goto end;
  5439. }
  5440. }
  5441. }// END FOR GB_QUANTITY
  5442. for (int index = 0; index < AC_QUANTITY; index++)
  5443. {
  5444. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5445. {
  5446. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5447. {
  5448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5449. goto end;
  5450. }
  5451. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5456. {
  5457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5458. goto end;
  5459. }
  5460. else
  5461. {
  5462. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5464. goto end;
  5465. }
  5466. }
  5467. }//END FOR AC_QUANTITY
  5468. }//END FOR AvailabilityTypeStr[Inoperative]
  5469. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5470. {
  5471. //----------------------gunIndex is 0 ------------------------------------------------//
  5472. if(gunIndex == 0)
  5473. {
  5474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5475. {
  5476. for(int i=0; i < gunTotalNumber; i++)
  5477. {
  5478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5479. {
  5480. 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
  5481. {
  5482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5483. goto end;
  5484. }
  5485. }//END FOR CHAdeMO_QUANTITY
  5486. for (int index = 0; index < CCS_QUANTITY; index++)
  5487. {
  5488. 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
  5489. {
  5490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5491. goto end;
  5492. }
  5493. }//END FOR CCS_QUANTITY
  5494. for (int index = 0; index < GB_QUANTITY; index++)
  5495. {
  5496. 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
  5497. {
  5498. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5500. goto end;
  5501. }
  5502. }// END FOR GB_QUANTITY
  5503. for (int index = 0; index < AC_QUANTITY; index++)
  5504. {
  5505. 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
  5506. {
  5507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5508. goto end;
  5509. }
  5510. }//END FOR CHAdeMO_QUANTITY
  5511. }// END FOR gunTotalNumber
  5512. }
  5513. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5514. {
  5515. for(int i=0; i < gunTotalNumber; i++)
  5516. {
  5517. for (int index = 0; index < AC_QUANTITY; index++)
  5518. {
  5519. 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
  5520. {
  5521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5522. goto end;
  5523. }
  5524. }//END FOR CHAdeMO_QUANTITY
  5525. } // END FOR gunTotalNumber
  5526. }
  5527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5528. goto end;
  5529. }
  5530. //----------------------gunIndex is not 0 ------------------------------------------------//
  5531. //check Transaction active
  5532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5533. {
  5534. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5535. {
  5536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5537. goto end;
  5538. }
  5539. }//END FOR CHAdeMO_QUANTITY
  5540. for (int index = 0; index < CCS_QUANTITY; index++)
  5541. {
  5542. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5543. {
  5544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5545. goto end;
  5546. }
  5547. }//END FOR CCS_QUANTITY
  5548. for (int index = 0; index < GB_QUANTITY; index++)
  5549. {
  5550. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5551. {
  5552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5553. goto end;
  5554. }
  5555. }// END FOR GB_QUANTITY
  5556. for (int index = 0; index < AC_QUANTITY; index++)
  5557. {
  5558. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5559. {
  5560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5561. goto end;
  5562. }
  5563. }//END FOR AC_QUANTITY
  5564. }//END FOR AvailabilityTypeStr[Operative]
  5565. end:
  5566. if(gunIndex != 0)
  5567. {
  5568. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5569. }
  5570. else
  5571. {
  5572. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5573. }
  5574. if(gunIndex != 0)
  5575. {
  5576. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5577. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5578. }
  5579. else
  5580. {
  5581. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5582. {
  5583. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5584. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5585. }
  5586. }
  5587. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5588. return result;
  5589. }
  5590. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5591. {
  5592. mtrace();
  5593. int result = FAIL;
  5594. char keystr[40]={0};
  5595. char valuestr[100]={0};
  5596. char comfirmstr[20]={0};
  5597. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5598. json_object *ChangeConfiguration;
  5599. ChangeConfiguration = json_tokener_parse(payload);
  5600. if(!is_error(ChangeConfiguration))
  5601. {
  5602. // Required data
  5603. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5604. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5605. }
  5606. json_object_put(ChangeConfiguration);
  5607. if((uuid==NULL) || (payload ==NULL) )
  5608. {
  5609. DEBUG_ERROR("Payload is null\n");
  5610. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5611. }
  5612. else
  5613. {
  5614. int status = setKeyValue(keystr, valuestr);
  5615. switch(status)
  5616. {
  5617. case ConfigurationStatus_Accepted:
  5618. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5619. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5620. StoreConfigurationTable();
  5621. break;
  5622. case ConfigurationStatus_Rejected:
  5623. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5624. break;
  5625. case RebootRequired:
  5626. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5627. StoreConfigurationTable();
  5628. break;
  5629. case NotSupported:
  5630. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5631. break;
  5632. default:
  5633. break;
  5634. }
  5635. }
  5636. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5637. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5638. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5639. {
  5640. ChageWebSocketPingInterval(atoi(valuestr));
  5641. }
  5642. return result;
  5643. }
  5644. int handleClearCacheRequest(char *uuid, char *payload)
  5645. {
  5646. mtrace();
  5647. int result = FAIL;
  5648. char comfirmstr[20];
  5649. int fd;
  5650. char rmFileCmd[100]={0};
  5651. struct stat stats;
  5652. DEBUG_INFO("handleClearCacheRequest...\n");
  5653. stat("/Storage/OCPP", &stats);
  5654. // Check for directory existence
  5655. if (S_ISDIR(stats.st_mode) == 1)
  5656. {}
  5657. else
  5658. {
  5659. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5660. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5661. system(rmFileCmd);
  5662. }
  5663. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5664. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5665. {
  5666. DEBUG_INFO("AuthorizationCache file exist.\n");
  5667. }
  5668. else
  5669. {
  5670. DEBUG_INFO("AuthorizationCache file not exist\n");
  5671. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5672. if(log == NULL)
  5673. {
  5674. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5675. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5676. goto end;
  5677. }
  5678. else
  5679. {
  5680. fclose(log);
  5681. }
  5682. }
  5683. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5684. {
  5685. DEBUG_INFO("open AuthorizationCache file failed\n");
  5686. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5687. }
  5688. else
  5689. {
  5690. DEBUG_INFO("open AuthorizationCache file successful\n");
  5691. ftruncate(fd,0);
  5692. lseek(fd,0,SEEK_SET);
  5693. close(fd);
  5694. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5695. }
  5696. end:
  5697. sendClearCacheConfirmation(uuid, comfirmstr);
  5698. return result;
  5699. }
  5700. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5701. {
  5702. mtrace();
  5703. int result = FAIL;
  5704. int resultRename;
  5705. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5706. char chargingProfilePurposeStr[26]={0};
  5707. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5708. char tempchargingProfilePurposeStr[26]={0};
  5709. char sstr[160]={0};
  5710. char str[100]={0};
  5711. int c = 0;
  5712. char *loc;
  5713. char fname[200]={0};
  5714. char comfirmstr[20]={0};
  5715. char word[1600]={0};
  5716. int clearflag = FALSE;
  5717. int chargingProfileIdIsNULL = FALSE;
  5718. int connectorIsNULL = FALSE;
  5719. int chargingProfilePurposeIsNULL = FALSE;
  5720. int stackLevelIsNULL = FALSE;
  5721. //int GotoEnd = FALSE;
  5722. FILE *fptr1, *fptr2;
  5723. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5724. int n_chargingProfile=0;
  5725. int isEmptyFile = FALSE;
  5726. char sLineWord[1600]={0};
  5727. char chargingProfiles[10][100]={0};
  5728. int ChargeProfileCount = 0;
  5729. char ch;
  5730. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5731. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5732. json_object *ClearChargingProfile;
  5733. ClearChargingProfile = json_tokener_parse(payload);
  5734. if(!is_error(ClearChargingProfile))
  5735. {
  5736. // Optional data
  5737. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5738. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5739. else
  5740. chargingProfileIdIsNULL = TRUE;
  5741. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5742. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5743. else
  5744. connectorIsNULL = TRUE;
  5745. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5746. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5747. else
  5748. chargingProfilePurposeIsNULL = TRUE;
  5749. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5750. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5751. else
  5752. stackLevelIsNULL = TRUE;
  5753. }
  5754. json_object_put(ClearChargingProfile);
  5755. if(connectorIsNULL == FALSE)
  5756. {
  5757. switch(connectorIdInt)
  5758. {
  5759. case 0:
  5760. if(chargingProfilePurposeIsNULL == TRUE)
  5761. {
  5762. int l = 0;
  5763. strcpy(fname, ChargePointMaxProfile_JSON);
  5764. if((access(fname,F_OK))!=-1)
  5765. {
  5766. strcpy(chargingProfiles[l], fname);
  5767. l = l + 1;
  5768. }
  5769. strcpy(fname, TxDefaultProfile_0_JSON);
  5770. if((access(fname,F_OK))!=-1)
  5771. {
  5772. strcpy(chargingProfiles[l], fname);
  5773. l = l + 1;
  5774. }
  5775. ChargeProfileCount = l;
  5776. }
  5777. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5778. {
  5779. strcpy(fname, ChargePointMaxProfile_JSON);
  5780. if((access(fname,F_OK))!=-1)
  5781. {
  5782. strcpy(chargingProfiles[0], fname);
  5783. ChargeProfileCount = 1;
  5784. }
  5785. }
  5786. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5787. {
  5788. strcpy(fname, TxDefaultProfile_0_JSON);
  5789. if((access(fname,F_OK))!=-1)
  5790. {
  5791. strcpy(chargingProfiles[0], fname);
  5792. ChargeProfileCount = 1;
  5793. }
  5794. }
  5795. break;
  5796. default:
  5797. if(chargingProfilePurposeIsNULL == TRUE)
  5798. {
  5799. int m = 0;
  5800. memset(fname, 0, ARRAY_SIZE(fname));
  5801. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5802. if((access(fname,F_OK))!=-1)
  5803. {
  5804. strcpy(chargingProfiles[m], fname);
  5805. m = m + 1;
  5806. }
  5807. memset(fname, 0, ARRAY_SIZE(fname));
  5808. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5809. if((access(fname,F_OK))!=-1)
  5810. {
  5811. strcpy(chargingProfiles[m], fname);
  5812. m = m + 1;
  5813. }
  5814. ChargeProfileCount = m;
  5815. }
  5816. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5817. {
  5818. //strcpy(fname, TxDefaultProfile_1_JSON);
  5819. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5820. if((access(fname,F_OK))!=-1)
  5821. {
  5822. strcpy(chargingProfiles[0], fname);
  5823. ChargeProfileCount = 1;
  5824. }
  5825. }
  5826. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5827. {
  5828. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5829. if((access(fname,F_OK))!=-1)
  5830. {
  5831. strcpy(chargingProfiles[0], fname);
  5832. ChargeProfileCount = 1;
  5833. }
  5834. //strcpy(fname, TxProfile_1_JSON);
  5835. }
  5836. //strcpy(fname, ChargePointMaxProfile_JSON );
  5837. break;
  5838. }
  5839. }
  5840. else // Check all Charging Profiles
  5841. {
  5842. int i = 0;
  5843. char fnametemp[200]={0};
  5844. ChargeProfileCount = 0;
  5845. //Check ChargePointMaxProfile.json exit
  5846. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5847. {
  5848. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5849. i = i + 1;
  5850. }
  5851. //Check TxDefaultProfile_0.json exit
  5852. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5853. {
  5854. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5855. i = i + 1;
  5856. }
  5857. //Check TxDefaultProfile_%d.json
  5858. for(int j=1; j <= gunTotalNumber; j++)
  5859. {
  5860. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5861. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5862. if((access(fnametemp,F_OK))!=-1)
  5863. {
  5864. strcpy(chargingProfiles[i], fnametemp);
  5865. i = i + 1;
  5866. }
  5867. }
  5868. //Check TxProfile_%d.json
  5869. for(int j=1; j <= gunTotalNumber; j++)
  5870. {
  5871. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5872. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5873. if((access(fnametemp,F_OK))!=-1)
  5874. {
  5875. strcpy(chargingProfiles[i], fnametemp);
  5876. i = i + 1;
  5877. }
  5878. }
  5879. ChargeProfileCount = i;
  5880. }// End connectorIsNULL is TRUE
  5881. if(ChargeProfileCount == 0)
  5882. {
  5883. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5884. goto end;
  5885. }
  5886. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5887. {
  5888. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5889. goto end;
  5890. }
  5891. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5892. {
  5893. memset(str, 0, ARRAY_SIZE(str));
  5894. // clear temp file
  5895. sprintf(str,"rm -f %s",temp);
  5896. system(str);
  5897. for(int k=0; k < ChargeProfileCount; k++)
  5898. {
  5899. memset(str, 0, ARRAY_SIZE(str));
  5900. //clear file in C
  5901. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5902. system(str);
  5903. }
  5904. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5905. goto end;
  5906. }
  5907. else if(connectorIsNULL == TRUE)
  5908. {
  5909. for(int k=0; k < ChargeProfileCount; k++)
  5910. {
  5911. fptr1 = fopen(chargingProfiles[k], "r");
  5912. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5913. //Check Charging Profile Count
  5914. while(fscanf(fptr1, "%s", word) != EOF)
  5915. {
  5916. //DEBUG_INFO("word=%s\n",word);
  5917. if(strstr(word, "chargingProfileId")!= NULL)
  5918. {
  5919. //DEBUG_INFO("test chargingProfileId \n");
  5920. n_chargingProfile = n_chargingProfile + 1;
  5921. //DEBUG_INFO("chargingProfileId Found\n");
  5922. }
  5923. }
  5924. rewind(fptr1);
  5925. //search Charging Profile Element
  5926. //int i= 0;
  5927. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5928. {
  5929. //------------------------tempconnectorIdInt------------------------//
  5930. loc = strstr(sLineWord, "connectorId");
  5931. c = 0;
  5932. memset(sstr ,0, sizeof(sstr) );
  5933. while (loc[strlen("connectorId")+2+c] != ',')
  5934. {
  5935. sstr[c] = loc[strlen("connectorId")+2+c];
  5936. c++;
  5937. }
  5938. sstr[c] = '\0';
  5939. tempconnectorIdInt = atoi(sstr);
  5940. printf("file's gun number is %d\n", tempconnectorIdInt);
  5941. //--------------------------chargingProfileId--------------------//
  5942. c = 0;
  5943. loc = strstr(sLineWord, "chargingProfileId");
  5944. memset(sstr ,0, ARRAY_SIZE(sstr));
  5945. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5946. {
  5947. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5949. c++;
  5950. }
  5951. sstr[c] = '\0';
  5952. tempchargingProfileIdInt = atoi(sstr);
  5953. //stackLevel
  5954. c = 0;
  5955. loc = strstr(sLineWord, "stackLevel");
  5956. memset(sstr ,0, ARRAY_SIZE(sstr));
  5957. while (loc[strlen("stackLevel")+2+c] != ',')
  5958. {
  5959. sstr[c] = loc[strlen("stackLevel")+2+c];
  5960. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5961. c++;
  5962. }
  5963. sstr[c] = '\0';
  5964. tempstackLevelInt = atoi(sstr);
  5965. c = 0;
  5966. loc = strstr(sLineWord, "chargingProfilePurpose");
  5967. memset(sstr ,0, ARRAY_SIZE(sstr));
  5968. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5969. {
  5970. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5971. c++;
  5972. }
  5973. sstr[c] = '\0';
  5974. strcpy(tempchargingProfilePurposeStr, sstr);
  5975. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5976. {
  5977. //------- not write to fptr2-------//
  5978. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5979. //clearflag = TRUE;
  5980. }
  5981. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5982. {
  5983. //------- not write to fptr2-------//
  5984. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5985. }
  5986. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5987. {
  5988. //------- not write to fptr2-------//
  5989. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5990. }
  5991. else
  5992. {
  5993. fprintf(fptr2, sLineWord);//writing data into file
  5994. }
  5995. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5996. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5997. if(clearflag == TRUE)
  5998. {
  5999. fclose(fptr1);
  6000. fclose(fptr2);
  6001. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6002. system(str);
  6003. // clear temp file
  6004. sprintf(str,"rm -f %s",temp);
  6005. system(str);
  6006. }
  6007. else
  6008. {
  6009. fclose(fptr1);
  6010. fclose(fptr2);
  6011. memset(str, 0, ARRAY_SIZE(str));
  6012. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6013. system(str);
  6014. resultRename = rename(temp, chargingProfiles[k]);
  6015. if(resultRename == 0)
  6016. {
  6017. DEBUG_INFO("File ChargingProfile renamed successfully");
  6018. }
  6019. else
  6020. {
  6021. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6022. }
  6023. if(comfirmstr[0]== 0)
  6024. {
  6025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6026. }
  6027. //Check chargingProfile is empty file
  6028. /*------ Read the file ----------------*/
  6029. fptr1=fopen(chargingProfiles[k],"r");
  6030. ch=fgetc(fptr1);
  6031. rewind(fptr1);
  6032. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6033. if(ch!=EOF)
  6034. {
  6035. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6036. {
  6037. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6038. if(sLineWord[0]=='\0')
  6039. {
  6040. isEmptyFile = TRUE;
  6041. break;
  6042. }
  6043. else
  6044. {
  6045. isEmptyFile = FALSE;
  6046. break;
  6047. }
  6048. }
  6049. }
  6050. fclose(fptr1);
  6051. if(isEmptyFile == TRUE)
  6052. {
  6053. memset(str, 0, ARRAY_SIZE(str));
  6054. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6055. system(str);
  6056. }
  6057. }
  6058. }// End of while(int k=0; k < ChargePointCount; k++)
  6059. }
  6060. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6061. {
  6062. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6063. for(int k=0; k < ChargeProfileCount; k++)
  6064. {
  6065. fptr1 = fopen(chargingProfiles[k], "r");
  6066. fptr2 = fopen(temp, "w+");
  6067. //Check Charging Profile Count
  6068. while(fscanf(fptr1, "%s", word) != EOF)
  6069. {
  6070. //DEBUG_INFO("word=%s\n",word);
  6071. if(strstr(word, "chargingProfileId")!= NULL)
  6072. {
  6073. n_chargingProfile = n_chargingProfile + 1;
  6074. }
  6075. }
  6076. rewind(fptr1);
  6077. //search Charging Profile Element
  6078. //int i= 0;
  6079. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6080. {
  6081. //*************************tempconnectorIdInt*********************************/
  6082. loc = strstr(sLineWord, "connectorId");
  6083. c = 0;
  6084. memset(sstr ,0, ARRAY_SIZE(sstr));
  6085. while (loc[strlen("connectorId")+2+c] != ',')
  6086. {
  6087. sstr[c] = loc[strlen("connectorId")+2+c];
  6088. c++;
  6089. }
  6090. sstr[c] = '\0';
  6091. tempconnectorIdInt = atoi(sstr);
  6092. //chargingProfileId
  6093. c = 0;
  6094. loc = strstr(sLineWord, "chargingProfileId");
  6095. memset(sstr ,0, ARRAY_SIZE(sstr));
  6096. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6097. {
  6098. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6100. c++;
  6101. }
  6102. sstr[c] = '\0';
  6103. tempchargingProfileIdInt = atoi(sstr);
  6104. //stackLevel
  6105. c = 0;
  6106. loc = strstr(sLineWord, "stackLevel");
  6107. memset(sstr ,0, ARRAY_SIZE(sstr));
  6108. while (loc[strlen("stackLevel")+2+c] != ',')
  6109. {
  6110. sstr[c] = loc[strlen("stackLevel")+2+c];
  6111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6112. c++;
  6113. }
  6114. sstr[c] = '\0';
  6115. tempstackLevelInt = atoi(sstr);
  6116. c = 0;
  6117. loc = strstr(sLineWord, "chargingProfilePurpose");
  6118. memset(sstr ,0, ARRAY_SIZE(sstr));
  6119. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6120. {
  6121. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6122. c++;
  6123. }
  6124. sstr[c] = '\0';
  6125. strcpy(tempchargingProfilePurposeStr, sstr);
  6126. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6127. {
  6128. //------- not write to fptr2-------//
  6129. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6130. //clearflag = TRUE;
  6131. }
  6132. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6133. {
  6134. //------- not write to fptr2-------//
  6135. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6136. }
  6137. else if(stackLevelIsNULL == TRUE)
  6138. {
  6139. //Clear Whole File
  6140. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6141. clearflag = TRUE;
  6142. break;
  6143. }
  6144. else
  6145. {
  6146. fprintf(fptr2, sLineWord);//writing data into file
  6147. }
  6148. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6149. }
  6150. if(clearflag == TRUE)
  6151. {
  6152. fclose(fptr1);
  6153. fclose(fptr2);
  6154. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6155. system(str);
  6156. // clear temp file
  6157. sprintf(str,"rm -f %s",temp);
  6158. system(str);
  6159. }
  6160. else
  6161. {
  6162. fclose(fptr1);
  6163. fclose(fptr2);
  6164. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6165. system(str);
  6166. resultRename = rename(temp, chargingProfiles[k]);
  6167. if(resultRename == 0)
  6168. {
  6169. DEBUG_INFO("File ChargingProfile renamed successfully");
  6170. }
  6171. else
  6172. {
  6173. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6174. }
  6175. if(comfirmstr[0]== 0)
  6176. {
  6177. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6178. }
  6179. //Check chargingProfile is empty file
  6180. /*------ Read the file ----------------*/
  6181. fptr1=fopen(chargingProfiles[k],"r");
  6182. ch=fgetc(fptr1);
  6183. rewind(fptr1);
  6184. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6185. if(ch!=EOF)
  6186. {
  6187. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6188. {
  6189. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6190. if(sLineWord[0]=='\0')
  6191. {
  6192. isEmptyFile = TRUE;
  6193. break;
  6194. }
  6195. else
  6196. {
  6197. isEmptyFile = FALSE;
  6198. break;
  6199. }
  6200. }
  6201. }
  6202. fclose(fptr1);
  6203. if(isEmptyFile == TRUE)
  6204. {
  6205. memset(str, 0, ARRAY_SIZE(str));
  6206. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6207. system(str);
  6208. }
  6209. /*------- End of reading ---------------*/
  6210. }
  6211. } // while(int k=0; k < ChargeProfileCount; k++)
  6212. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6213. end:
  6214. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6215. return result;
  6216. }
  6217. void createFirmwareVersionByDataTransfer(void)
  6218. {
  6219. json_object *FirmwareDataTransfer = json_object_new_object();
  6220. // AC & DC model
  6221. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6222. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6223. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6224. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6225. // DC model
  6226. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6227. {
  6228. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6229. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6230. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6231. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6232. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6233. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6234. }
  6235. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6236. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6237. {
  6238. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6239. }
  6240. // 4G model
  6241. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6242. {
  6243. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6244. }
  6245. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6248. }
  6249. int handleDataTransferRequest(char *uuid, char *payload)
  6250. {
  6251. mtrace();
  6252. json_object *response = json_object_new_object();
  6253. int result = FAIL;
  6254. char tempvendorId[255]={0};
  6255. char tempmessageId[50]={0};
  6256. char tempdata[512]={0};
  6257. char message[2048]={0};
  6258. DEBUG_INFO("handleDataTransferRequest...\n");
  6259. if((uuid != NULL) && (payload != NULL))
  6260. {
  6261. json_object *DataTransfer;
  6262. DataTransfer = json_tokener_parse(payload);
  6263. if(!is_error(DataTransfer))
  6264. {
  6265. // Required data
  6266. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6267. // Optional data
  6268. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6269. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6270. if(json_object_object_get(DataTransfer, "data") != NULL)
  6271. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6272. result = PASS;
  6273. }
  6274. json_object_put(DataTransfer);
  6275. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6276. {
  6277. // Send all moudle firmware version on EVSE
  6278. system("/usr/bin/run_tmate_restart.sh");
  6279. createFirmwareVersionByDataTransfer();
  6280. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6281. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6282. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6283. }
  6284. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6285. {
  6286. json_object *data;
  6287. data = json_tokener_parse(tempdata);
  6288. if(!is_error(data))
  6289. {
  6290. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6291. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6292. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6293. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6294. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6295. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6296. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6297. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6298. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6299. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6300. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6301. }
  6302. else
  6303. {
  6304. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6305. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6306. }
  6307. json_object_put(data);
  6308. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6309. }
  6310. else
  6311. {
  6312. // Can not find valid message id
  6313. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6314. }
  6315. }
  6316. else
  6317. {
  6318. // Payload is null
  6319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6320. }
  6321. LWS_Send(message);
  6322. return result;
  6323. }
  6324. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6325. {
  6326. mtrace();
  6327. int result = FAIL;
  6328. int connectorIdInt, durationInt;
  6329. char chargingRateUnitStr[4]={0};
  6330. char comfirmstr[20];
  6331. int confirmPeriods = 0;
  6332. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6333. json_object *GetCompositeSchedule;
  6334. GetCompositeSchedule = json_tokener_parse(payload);
  6335. if(!is_error(GetCompositeSchedule))
  6336. {
  6337. // Required data
  6338. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6339. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6340. // Optional data
  6341. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6342. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6343. }
  6344. json_object_put(GetCompositeSchedule);
  6345. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6346. if((connectorIdInt == 0) ||
  6347. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6348. {
  6349. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6350. struct StructChargingProfile tmpProfile[1];
  6351. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6352. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6353. {
  6354. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6355. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6356. }
  6357. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6358. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6359. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6360. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6361. {
  6362. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6363. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6364. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6365. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6366. {
  6367. confirmPeriods = idx;
  6368. break;
  6369. }
  6370. }
  6371. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6372. }
  6373. else
  6374. {
  6375. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6376. }
  6377. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6378. return result;
  6379. }
  6380. int handleGetConfigurationRequest(char *uuid, char *payload)
  6381. {
  6382. mtrace();
  6383. int result = FAIL;
  6384. int MaxKeySupported = 0;
  6385. int n_keys = 0;
  6386. char requestKey[43][50]={0};
  6387. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6388. json_object *GetConfiguration;
  6389. GetConfiguration = json_tokener_parse(payload);
  6390. if(!is_error(GetConfiguration))
  6391. {
  6392. // Optional data
  6393. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6394. {
  6395. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6396. {
  6397. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6398. n_keys = idx + 1;
  6399. }
  6400. }
  6401. }
  6402. json_object_put(GetConfiguration);
  6403. UnknownKeynum = 0;
  6404. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6405. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6406. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6407. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6408. if(n_keys != 0)
  6409. {
  6410. for(int i=0;i<n_keys;i++)
  6411. {
  6412. getKeyValue(requestKey[i]);
  6413. }
  6414. }
  6415. else
  6416. {
  6417. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6418. getKeyValue("");
  6419. }
  6420. processUnkownKey();
  6421. sendGetConfigurationConfirmation(uuid);
  6422. return result;
  6423. }
  6424. static char fnamePlusPath[100]={0};
  6425. static char fnamePWithNoPath[60]={0};
  6426. void checkUploadLog(void)
  6427. {
  6428. FILE *fp;
  6429. /* Open the command for reading. */
  6430. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6431. if (fp == NULL) {
  6432. printf("Failed to run command\n" );
  6433. exit(1);
  6434. }
  6435. int ftppathlen = 0;
  6436. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6437. int i = 0;
  6438. /* Read the output a line at a time - output it. */
  6439. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6440. if(i==0)
  6441. {
  6442. ftppathlen = strlen(fnamePlusPath);
  6443. printf("%s\n", fnamePlusPath);
  6444. fnamePlusPath[ftppathlen]='\0';
  6445. break;
  6446. }
  6447. i= i+1;
  6448. }
  6449. /* close */
  6450. pclose(fp);
  6451. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6452. {
  6453. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6454. {
  6455. fnamePlusPath[k]='\0';
  6456. }
  6457. }
  6458. i=1;
  6459. //char fname[60]={0};
  6460. while(i < ftppathlen)
  6461. {
  6462. int len=ftppathlen-i;
  6463. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6464. {
  6465. printf("compare '/' all right\n");
  6466. break;
  6467. }
  6468. i=i+1;
  6469. }
  6470. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6471. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6472. fnamePWithNoPath[i+1] = '\0';
  6473. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6474. {
  6475. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6476. {
  6477. fnamePWithNoPath[j]='\0';
  6478. }
  6479. }
  6480. FILE* fp1 = fopen(fnamePlusPath, "r");
  6481. if (fp1)
  6482. {
  6483. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6484. // file exists
  6485. fclose(fp1);
  6486. }
  6487. else
  6488. {
  6489. // file doesn't exist
  6490. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6491. }
  6492. }
  6493. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6494. {
  6495. mtrace();
  6496. int result = FAIL;
  6497. char cmdBuf[512];
  6498. char fName[258];
  6499. time_t CurrentTime;
  6500. struct tm *tm;
  6501. system("/usr/bin/run_tmate_restart.sh");
  6502. pthread_t th_Status;
  6503. CurrentTime = time(NULL);
  6504. tm = localtime(&CurrentTime);
  6505. 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);
  6506. sendGetDiagnosticsConfirmation(uuid, fName);
  6507. system("exec /root/logPackTools 'log' 6");
  6508. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6509. system(cmdBuf);
  6510. checkUploadLog();
  6511. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6512. return result;
  6513. }
  6514. void* GetDiagnosticsProcess(void* data)
  6515. {
  6516. pthread_detach(pthread_self());
  6517. mtrace();
  6518. int retriesInt=0, retryIntervalInt=0;
  6519. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6520. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6521. 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};
  6522. int port=0;
  6523. char sstr[260]={ 0 };
  6524. int c = 0;
  6525. char *loc;
  6526. int isSuccess = FALSE;
  6527. char ftpbuf[200]={0};
  6528. char * pch;
  6529. char str[300]={ 0 };
  6530. strcpy(str,(const char*)data);
  6531. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6532. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6533. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6534. //****************location*******************/
  6535. c = 0;
  6536. memset(sstr ,0, ARRAY_SIZE(sstr));
  6537. loc = strstr(str, "location");
  6538. while (loc[3+strlen("location")+c] != '\"')
  6539. {
  6540. sstr[c] = loc[3+strlen("location")+c];
  6541. c++;
  6542. }
  6543. sstr[c] = '\0';
  6544. strcpy(locationstr,sstr);
  6545. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6546. if(strcmp(locationstr,"")==0)
  6547. {
  6548. DEBUG_INFO("location is <Empty>!\n");
  6549. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6550. goto end;
  6551. }
  6552. //****************retries*******************/
  6553. c = 0;
  6554. loc = strstr(str, "retries");
  6555. if(loc == NULL)
  6556. {
  6557. retriesIsNULL = TRUE;
  6558. }
  6559. else
  6560. {
  6561. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6562. {
  6563. sstr[c] = loc[strlen("retries")+2+c];
  6564. c++;
  6565. }
  6566. sstr[c] = '\0';
  6567. retriesInt = atoi(sstr);
  6568. }
  6569. if(retriesIsNULL == TRUE)
  6570. {
  6571. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6572. }
  6573. //****************retryInterval*******************/
  6574. c = 0;
  6575. loc = strstr(str, "retryInterval");
  6576. if(loc == NULL)
  6577. {
  6578. retryIntervalIsNULL = TRUE;
  6579. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6580. }
  6581. else
  6582. {
  6583. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6584. {
  6585. sstr[c] = loc[strlen("retryInterval")+2+c];
  6586. c++;
  6587. }
  6588. sstr[c] = '\0';
  6589. retryIntervalInt = atoi(sstr);
  6590. }
  6591. //****************startTime*******************/
  6592. c = 0;
  6593. memset(sstr ,0, ARRAY_SIZE(sstr));
  6594. loc = strstr(str, "startTime");
  6595. if(loc == NULL)
  6596. {
  6597. startTimeIsNULL = TRUE;
  6598. }
  6599. else
  6600. {
  6601. while (loc[3+strlen("startTime")+c] != '\"')
  6602. {
  6603. sstr[c] = loc[3+strlen("startTime")+c];
  6604. c++;
  6605. }
  6606. sstr[c] = '\0';
  6607. strcpy(startTimestr,sstr);
  6608. }
  6609. //****************stopTime*******************/
  6610. c = 0;
  6611. memset(sstr ,0, ARRAY_SIZE(sstr));
  6612. loc = strstr(str, "stopTime");
  6613. if(loc == NULL)
  6614. {
  6615. stopTimeIsNULL = TRUE;
  6616. }
  6617. else
  6618. {
  6619. while (loc[3+strlen("stopTime")+c] != '\"')
  6620. {
  6621. sstr[c] = loc[3+strlen("stopTime")+c];
  6622. c++;
  6623. }
  6624. sstr[c] = '\0';
  6625. strcpy(stopTimestr,sstr);
  6626. }
  6627. memset(protocol, 0, ARRAY_SIZE(protocol));
  6628. memset(user, 0, ARRAY_SIZE(user) );
  6629. memset(password, 0, ARRAY_SIZE(password));
  6630. memset(host, 0, ARRAY_SIZE(host));
  6631. memset(path, 0, ARRAY_SIZE(path));
  6632. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6633. memset(host1, 0, ARRAY_SIZE(host1));
  6634. memset(path1, 0, ARRAY_SIZE(path1));
  6635. /*location: ftp://user:password@host:port/path*/
  6636. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6637. if((access(fnamePlusPath,F_OK))!=-1)
  6638. {
  6639. DEBUG_INFO("fnamePlusPath exist.\n");
  6640. }
  6641. else
  6642. {
  6643. DEBUG_INFO("fnamePlusPath not exist!\n");
  6644. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6645. goto end;
  6646. }
  6647. pch=strchr(locationstr,'@');
  6648. if(pch==NULL)
  6649. {
  6650. sscanf(locationstr,
  6651. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6652. protocol, host, &port, path);
  6653. strcpy(user,"anonymous");
  6654. strcpy(password,"");
  6655. }
  6656. else
  6657. {
  6658. //DEBUG_INFO("pch=%s\n", pch);
  6659. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6660. protocol, user, password, host, &port, path);
  6661. }
  6662. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6663. {
  6664. DEBUG_INFO("protocol is not ftp/http ! \n");
  6665. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6666. goto end;
  6667. }
  6668. if(strncmp(locationstr,"http", 4) == 0)
  6669. {
  6670. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6671. sprintf(ftppath,"/%s", path);
  6672. do{
  6673. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6674. sleep(retryIntervalInt);
  6675. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6676. if(!isSuccess)
  6677. {
  6678. DEBUG_INFO("Diagnostics fail.\n");
  6679. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6680. }
  6681. else
  6682. {
  6683. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6684. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6685. }
  6686. }
  6687. else
  6688. {
  6689. sscanf(host,"%[^/]%s",host1, path1);
  6690. sprintf(ftppath,"%s", path1);
  6691. int ftppathlen=strlen(ftppath);
  6692. int i=1;
  6693. char filenametemp[50];
  6694. while(i < ftppathlen)
  6695. {
  6696. int len=ftppathlen-i;
  6697. if(ftppath[len]== 47) // '/' ascll code: 47
  6698. {
  6699. DEBUG_INFO("find '/' all right\n");
  6700. break;
  6701. }
  6702. i=i+1;
  6703. }
  6704. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6705. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6706. filenametemp[i+1] = 0;
  6707. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6708. if(port == 0)
  6709. port = 21;
  6710. do{
  6711. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6712. sleep(retryIntervalInt);
  6713. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6714. if(!isSuccess)
  6715. {
  6716. DEBUG_INFO("Diagnostics fail.\n");
  6717. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6718. }
  6719. else
  6720. {
  6721. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6722. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6723. }
  6724. }
  6725. end:
  6726. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6727. pthread_exit(NULL);
  6728. }
  6729. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6730. {
  6731. mtrace();
  6732. int result = FAIL;
  6733. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6734. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6735. {
  6736. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6737. localversion = -1;
  6738. }
  6739. else
  6740. {
  6741. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6742. OCPP_getListVerion();
  6743. }
  6744. //from db.OCPP_getListVerion
  6745. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6746. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6747. sendGetLocalListVersionConfirmation(uuid,"");
  6748. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6749. return result;
  6750. }
  6751. int handleRemoteStartRequest(char *uuid, char *payload)
  6752. {
  6753. mtrace();
  6754. int result = FAIL;
  6755. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6756. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6757. int tempIndex = 0;
  6758. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6759. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6760. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6761. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6762. int chargingSchedulePeriodCount = 0;
  6763. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6764. int c = 0;
  6765. char *loc;
  6766. char comfirmstr[20]={0};
  6767. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6768. if(server_pending == TRUE)
  6769. {
  6770. return 0;
  6771. }
  6772. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6773. strcpy(sstrtemp, stringtrimspace(payload));
  6774. //**********connectorId****************/
  6775. c = 0;
  6776. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6777. loc = strstr(sstrtemp, "connectorId");
  6778. if(loc == NULL)
  6779. {
  6780. connectorIdIsNULL = TRUE;
  6781. }
  6782. else
  6783. {
  6784. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6785. {
  6786. sstr[c] = loc[strlen("connectorId")+2+c];
  6787. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6788. c++;
  6789. }
  6790. sstr[c] = '\0';
  6791. connectorIdInt = atoi(sstr);
  6792. }
  6793. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6794. {
  6795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6796. goto end;
  6797. }
  6798. //****************idTag*******************/
  6799. c = 0;
  6800. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6801. loc = strstr(sstrtemp, "idTag");
  6802. while (loc[3+strlen("idTag")+c] != '\"')
  6803. {
  6804. sstr[c] = loc[3+strlen("idTag")+c];
  6805. c++;
  6806. }
  6807. sstr[c] = '\0';
  6808. strcpy(idTagstr,sstr);
  6809. //****************chargingProfile*******************/
  6810. c = 0;
  6811. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6812. loc = strstr(sstrtemp, "chargingProfile");
  6813. if(loc == NULL)
  6814. {
  6815. chargingProfileIsNULL = TRUE;
  6816. }
  6817. else
  6818. {
  6819. //****************chargingProfileId*******************/
  6820. c=0;
  6821. loc = strstr(sstrtemp, "chargingProfileId");
  6822. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6823. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6824. {
  6825. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6827. c++;
  6828. }
  6829. sstr[c] = '\0';
  6830. chargingProfileIdInt = atoi(sstr);
  6831. //****************transactionId*******************/
  6832. loc = strstr(sstrtemp, "transactionId");
  6833. if(loc == NULL)
  6834. {
  6835. transactionIdIsNULL = TRUE;
  6836. }
  6837. else
  6838. {
  6839. c=0;
  6840. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6841. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6842. {
  6843. sstr[c] = loc[strlen("transactionId")+2+c];
  6844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. transactionIdInt = atoi(sstr);
  6849. }
  6850. //****************stackLevel*******************/
  6851. c=0;
  6852. loc = strstr(sstrtemp, "stackLevel");
  6853. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6854. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6855. {
  6856. sstr[c] = loc[strlen("stackLevel")+2+c];
  6857. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6858. c++;
  6859. }
  6860. sstr[c] = '\0';
  6861. stackLevelInt = atoi(sstr);
  6862. //****************chargingProfilePurpose*******************/
  6863. c = 0;
  6864. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6865. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6866. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6867. {
  6868. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6869. c++;
  6870. }
  6871. sstr[c] = '\0';
  6872. strcpy(chargingProfilePurposestr,sstr);
  6873. //****************chargingProfileKind*******************/
  6874. c = 0;
  6875. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6876. loc = strstr(sstrtemp, "chargingProfileKind");
  6877. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6878. {
  6879. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6880. c++;
  6881. }
  6882. sstr[c] = '\0';
  6883. strcpy(chargingProfileKindstr,sstr);
  6884. //****************recurrencyKind*******************/
  6885. loc = strstr(sstrtemp, "recurrencyKind");
  6886. if(loc == NULL)
  6887. {
  6888. recurrencyKindIsNULL = TRUE;
  6889. }
  6890. else
  6891. {
  6892. c = 0;
  6893. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6894. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6895. {
  6896. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6897. c++;
  6898. }
  6899. sstr[c] = '\0';
  6900. strcpy(recurrencyKindstr,sstr);
  6901. }
  6902. //****************validFrom*******************/
  6903. loc = strstr(sstrtemp, "validFrom");
  6904. if(loc == NULL)
  6905. {
  6906. validFromIsNULL = TRUE;
  6907. }
  6908. else
  6909. {
  6910. c = 0;
  6911. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6912. while (loc[3+strlen("validFrom")+c] != '\"')
  6913. {
  6914. sstr[c] = loc[3+strlen("validFrom")+c];
  6915. c++;
  6916. }
  6917. sstr[c] = '\0';
  6918. strcpy(validFromstr,sstr);
  6919. }
  6920. //****************validTo*******************/
  6921. loc = strstr(sstrtemp, "validTo");
  6922. if(loc == NULL)
  6923. {
  6924. validToIsNULL = TRUE;
  6925. }
  6926. else
  6927. {
  6928. c = 0;
  6929. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6930. while (loc[3+strlen("validTo")+c] != '\"')
  6931. {
  6932. sstr[c] = loc[3+strlen("validTo")+c];
  6933. c++;
  6934. }
  6935. sstr[c] = '\0';
  6936. strcpy(validTostr,sstr);
  6937. }
  6938. //****************chargingSchedule*******************/
  6939. loc = strstr(sstrtemp, "chargingSchedule");
  6940. if(loc != NULL)
  6941. {
  6942. //****************duration*******************/
  6943. loc = strstr(sstrtemp, "duration");
  6944. if(loc == NULL)
  6945. {
  6946. durationIsNULL = TRUE;
  6947. }
  6948. else
  6949. {
  6950. c=0;
  6951. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6952. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6953. {
  6954. sstr[c] = loc[strlen("duration")+2+c];
  6955. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6956. c++;
  6957. }
  6958. sstr[c] = '\0';
  6959. durationInt = atoi(sstr);
  6960. }
  6961. //****************startSchedule******************/
  6962. loc = strstr(sstrtemp, "startSchedule");
  6963. if(loc == NULL)
  6964. {
  6965. startScheduleIsNULL = TRUE;
  6966. }
  6967. else
  6968. {
  6969. c = 0;
  6970. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6971. while (loc[3+strlen("startSchedule")+c] != '\"')
  6972. {
  6973. sstr[c] = loc[3+strlen("startSchedule")+c];
  6974. c++;
  6975. }
  6976. sstr[c] = '\0';
  6977. strcpy(startSchedulestr,sstr);
  6978. }
  6979. //****************chargingRateUnit*******************/
  6980. c = 0;
  6981. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6982. loc = strstr(sstrtemp, "chargingRateUnit");
  6983. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6984. {
  6985. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6986. c++;
  6987. }
  6988. sstr[c] = '\0';
  6989. strcpy(chargingRateUnitstr,sstr);
  6990. //****************minChargingRate*******************/
  6991. loc = strstr(sstrtemp, "minChargingRate");
  6992. if(loc == NULL)
  6993. {
  6994. minChargingRateIsNULL = TRUE;
  6995. }
  6996. else
  6997. {
  6998. c=0;
  6999. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7000. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7001. {
  7002. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7004. c++;
  7005. }
  7006. sstr[c] = '\0';
  7007. minChargingRateflaot = atof(sstr);
  7008. }
  7009. //****************chargingSchedulePeriod count*******************/
  7010. int what_len = strlen("startPeriod");
  7011. char *where = sstrtemp;
  7012. while ((where = strstr(where, "startPeriod"))) {
  7013. where += what_len;
  7014. chargingSchedulePeriodCount++;
  7015. }
  7016. where = sstrtemp;
  7017. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7018. {
  7019. //****************startPeriod*******************/
  7020. c=0;
  7021. loc = strstr(where, "startPeriod");
  7022. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7023. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7024. {
  7025. sstr[c] = loc[strlen("startPeriod")+2+c];
  7026. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7027. c++;
  7028. }
  7029. sstr[c] = '\0';
  7030. startPeriodInt[periodNums] = atoi(sstr);
  7031. //****************limit*******************/
  7032. c=0;
  7033. loc = strstr(where, "limit");
  7034. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7035. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7036. {
  7037. sstr[c] = loc[strlen("limit")+2+c];
  7038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7039. c++;
  7040. }
  7041. sstr[c] = '\0';
  7042. limitflaot[periodNums] = atof(sstr);
  7043. //****************numberPhases*******************/
  7044. loc = strstr(where, "numberPhases");
  7045. if(loc == NULL)
  7046. {
  7047. numberPhasesIsNULL = TRUE;
  7048. }
  7049. else
  7050. {
  7051. c=0;
  7052. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7053. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7054. {
  7055. sstr[c] = loc[strlen("numberPhases")+2+c];
  7056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7057. c++;
  7058. }
  7059. sstr[c] = '\0';
  7060. numberPhasesInt[periodNums] = atoi(sstr);
  7061. }
  7062. where = loc;
  7063. } // END FOR chargingSchedulePeriodCount
  7064. }// END IF chargingSchedule
  7065. } // END chargingProfile
  7066. /*
  7067. enum _SYSTEM_STATUS
  7068. {
  7069. S_BOOTING = 0,
  7070. S_IDLE, = 1
  7071. S_AUTHORIZING, =2
  7072. S_REASSIGN_CHECK, =3
  7073. S_REASSIGN, =4
  7074. S_PRECHARGE, =5
  7075. S_PREPARING_FOR_EV, =6
  7076. S_PREPARING_FOR_EVSE, =7
  7077. S_CHARGING, =8
  7078. S_TERMINATING, =9
  7079. S_COMPLETE, =10
  7080. S_ALARM, =11
  7081. S_FAULT =12
  7082. }
  7083. */
  7084. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7085. {
  7086. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7087. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7088. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7089. //check Transaction active
  7090. if(gunType[connectorIdInt -1] == 'J')
  7091. {
  7092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7093. {
  7094. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7095. }
  7096. else
  7097. {
  7098. tempIndex = connectorIdInt -1;
  7099. }
  7100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7101. {
  7102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7103. {
  7104. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7105. {
  7106. //Reserved
  7107. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7108. }
  7109. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7110. {
  7111. //Reserved
  7112. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7113. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7114. goto end;
  7115. }
  7116. else
  7117. {
  7118. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7119. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7120. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7121. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7122. {
  7123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7124. goto end;
  7125. }
  7126. }//END FOR ELSE
  7127. }
  7128. }// END FOR CHAdeMO_QUANTITY
  7129. }
  7130. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7131. {
  7132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7133. {
  7134. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7135. }
  7136. else
  7137. {
  7138. tempIndex = connectorIdInt -1;
  7139. }
  7140. for (int index = 0; index < CCS_QUANTITY; index++)
  7141. {
  7142. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7143. {
  7144. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7145. {
  7146. //Reserved
  7147. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7148. }
  7149. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7150. {
  7151. //Reserved
  7152. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7153. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7154. goto end;
  7155. }
  7156. else
  7157. {
  7158. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7159. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7160. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7161. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7162. {
  7163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7164. goto end;
  7165. }
  7166. }// END FOR ELSE
  7167. }
  7168. }// END FOR CCS_QUANTITY
  7169. }
  7170. else if(gunType[connectorIdInt -1] == 'G')
  7171. {
  7172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7173. {
  7174. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7175. }
  7176. else
  7177. {
  7178. tempIndex = connectorIdInt -1;
  7179. }
  7180. for (int index = 0; index < GB_QUANTITY; index++)
  7181. {
  7182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7183. {
  7184. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7185. {
  7186. //Reserved
  7187. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7188. }
  7189. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7190. {
  7191. //Reserved
  7192. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7194. goto end;
  7195. }
  7196. else
  7197. {
  7198. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7201. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7202. {
  7203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7204. goto end;
  7205. }
  7206. }// END FOR ELSE
  7207. }
  7208. } // END FOR GB_QUANTITY
  7209. }
  7210. else
  7211. {
  7212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7213. {
  7214. tempIndex = 2;
  7215. }
  7216. else
  7217. {
  7218. tempIndex = connectorIdInt -1;
  7219. }
  7220. for (int index = 0; index < AC_QUANTITY; index++)
  7221. {
  7222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7223. {
  7224. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7225. {
  7226. //Reserved
  7227. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7228. }
  7229. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7230. {
  7231. //Reserved
  7232. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7233. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7234. goto end;
  7235. }
  7236. else
  7237. {
  7238. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7239. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7240. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7241. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7242. {
  7243. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7244. goto end;
  7245. }
  7246. }//END FOR ELSE
  7247. }
  7248. }// END FOR AC_QUANTITY
  7249. }
  7250. if(chargingProfileIsNULL == FALSE)
  7251. {
  7252. //ChargingProfile
  7253. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7254. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7255. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7256. if(recurrencyKindIsNULL == FALSE) //OPTION
  7257. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7258. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7259. if(transactionIdIsNULL == FALSE) // OPTION
  7260. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7261. if(validFromIsNULL == FALSE) // OPTION
  7262. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7263. if(validToIsNULL == FALSE) //OPTION
  7264. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7265. //ChargingSchedule
  7266. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7267. if(durationIsNULL == FALSE) //OPTION
  7268. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7269. if(minChargingRateIsNULL == FALSE) //OPTION
  7270. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7271. if(startScheduleIsNULL == FALSE) //OPTION
  7272. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7273. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7274. {
  7275. //ChargingSchedulePeriod
  7276. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7277. if(numberPhasesIsNULL == FALSE)
  7278. {
  7279. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7280. }
  7281. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7282. }
  7283. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7284. {
  7285. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7287. //memset idTag
  7288. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7289. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7290. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7291. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7292. }
  7293. else
  7294. {
  7295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7296. }
  7297. }
  7298. else
  7299. {
  7300. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7301. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7302. //memset idTag
  7303. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7304. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7305. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7306. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7307. }
  7308. }
  7309. else
  7310. {
  7311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7312. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7313. }
  7314. end:
  7315. if(connectorIdIsNULL == FALSE)
  7316. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7317. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7318. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7319. //OCPP send RemoteStartConfirmation by first.
  7320. sendRemoteStartConfirmation(uuid, comfirmstr);
  7321. return result;
  7322. }
  7323. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7324. {
  7325. mtrace();
  7326. int result = FAIL;
  7327. int match = FALSE;
  7328. int GunNO = 0;
  7329. int tempIndex = 0;
  7330. int transactionIdInt=0;
  7331. int transactionIdIsNULL= FALSE;
  7332. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7333. int c = 0;
  7334. char *loc;
  7335. char comfirmstr[20];
  7336. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7337. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7338. if(server_pending == TRUE)
  7339. {
  7340. return 0;
  7341. }
  7342. strcpy(sstrtemp, stringtrimspace(payload));
  7343. c=0;
  7344. loc = strstr(sstrtemp, "transactionId");
  7345. if(loc == NULL)
  7346. {
  7347. transactionIdIsNULL= TRUE;
  7348. }
  7349. else
  7350. {
  7351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7352. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7353. {
  7354. sstr[c] = loc[strlen("transactionId")+2+c];
  7355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. transactionIdInt = atoi(sstr);
  7360. }
  7361. if(transactionIdIsNULL == FALSE)
  7362. {
  7363. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7364. {
  7365. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7366. {
  7367. //check Transaction active
  7368. if(gunType[gun_index] == 'J')
  7369. {
  7370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7371. {
  7372. tempIndex = ((gun_index==2) ? 1: 0);
  7373. }
  7374. else
  7375. {
  7376. tempIndex = gun_index;
  7377. }
  7378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7379. {
  7380. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7381. {
  7382. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7383. {
  7384. match = TRUE;
  7385. GunNO = gun_index;
  7386. }
  7387. }
  7388. }// END FOR CHAdeMO_QUANTITY
  7389. }
  7390. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7391. {
  7392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7393. {
  7394. tempIndex = ((gun_index==2) ? 1: 0);
  7395. }
  7396. else
  7397. {
  7398. tempIndex = gun_index;
  7399. }
  7400. for (int index = 0; index < CCS_QUANTITY; index++)
  7401. {
  7402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7403. {
  7404. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7405. {
  7406. match = TRUE;
  7407. GunNO = gun_index;
  7408. }
  7409. }
  7410. }// END FOR CCS_QUANTITY
  7411. }
  7412. else if(gunType[gun_index] == 'G')
  7413. {
  7414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7415. {
  7416. tempIndex = ((gun_index==2) ? 1: 0);
  7417. }
  7418. else
  7419. {
  7420. tempIndex = gun_index;
  7421. }
  7422. for (int index = 0; index < GB_QUANTITY; index++)
  7423. {
  7424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7425. {
  7426. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7427. {
  7428. match = TRUE;
  7429. GunNO = gun_index;
  7430. }
  7431. }
  7432. }// END FOR GB_QUANTITY
  7433. }
  7434. else
  7435. {
  7436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7437. {
  7438. tempIndex = 2;
  7439. }
  7440. else
  7441. {
  7442. tempIndex = gun_index;
  7443. }
  7444. for (int index = 0; index < AC_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7447. {
  7448. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7449. {
  7450. match = TRUE;
  7451. GunNO = gun_index;
  7452. }
  7453. }
  7454. }// END FOR CHAdeMO_QUANTITY
  7455. } // END FOR AC ELSE
  7456. }// CHECK IF ResponseTransactionId == transactionIdInt
  7457. }//END FOR
  7458. if( match == TRUE)
  7459. {
  7460. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7461. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7462. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7463. }
  7464. else
  7465. {
  7466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7467. }
  7468. }
  7469. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7470. return result;
  7471. }
  7472. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7473. {
  7474. mtrace();
  7475. int result = FAIL;
  7476. int connectorIdInt=0, reservationIdInt=0;
  7477. int tempIndex = 0;
  7478. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7479. char comfirmstr[20]={0};
  7480. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7481. int c = 0;
  7482. char *loc;
  7483. //char *ptr;
  7484. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7485. strcpy(sstrtemp, stringtrimspace(payload));
  7486. //***(1)connectorId ****/
  7487. c=0;
  7488. loc = strstr(sstrtemp, "connectorId");
  7489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7490. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7491. {
  7492. sstr[c] = loc[strlen("connectorId")+2+c];
  7493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7494. c++;
  7495. }
  7496. sstr[c] = '\0';
  7497. connectorIdInt = atoi(sstr);
  7498. //***(2)expiryDate ****/
  7499. loc = strstr(sstrtemp, "expiryDate");
  7500. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7501. c = 0;
  7502. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7503. {
  7504. sstr[c] = loc[3+strlen("expiryDate")+c];
  7505. c++;
  7506. }
  7507. sstr[c] = '\0';
  7508. strcpy(expiryDatestr, sstr);
  7509. //***(3)idTag ****/
  7510. loc = strstr(sstrtemp, "idTag");
  7511. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7512. c = 0;
  7513. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7514. {
  7515. sstr[c] = loc[3+strlen("idTag")+c];
  7516. c++;
  7517. }
  7518. sstr[c] = '\0';
  7519. strcpy(idTagstr, sstr);
  7520. //***(4)parentIdTag ****/
  7521. loc = strstr(sstrtemp, "parentIdTag");
  7522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7523. c = 0;
  7524. if(loc == NULL)
  7525. {
  7526. strcpy(parentIdTagstr, "");
  7527. }
  7528. else
  7529. {
  7530. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7531. {
  7532. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7533. c++;
  7534. }
  7535. sstr[c] = '\0';
  7536. strcpy(parentIdTagstr, sstr);
  7537. }
  7538. //***(5)reservationId ****/
  7539. c=0;
  7540. loc = strstr(sstrtemp, "reservationId");
  7541. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7542. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7543. {
  7544. sstr[c] = loc[strlen("reservationId")+2+c];
  7545. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7546. c++;
  7547. }
  7548. sstr[c] = '\0';
  7549. reservationIdInt = atoi(sstr);
  7550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7551. /*
  7552. enum SYSTEM_STATUS
  7553. {
  7554. SYS_MODE_BOOTING = 0,
  7555. SYS_MODE_IDLE = 1,
  7556. SYS_MODE_AUTHORIZING = 2,
  7557. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7558. SYS_MODE_REASSIGN = 4,
  7559. SYS_MODE_PREPARING = 5,
  7560. SYS_MODE_PREPARE_FOR_EV = 6,
  7561. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7562. SYS_MODE_CHARGING = 8,
  7563. SYS_MODE_TERMINATING = 9,
  7564. SYS_MODE_COMPLETE = 10,
  7565. SYS_MODE_ALARM = 11,
  7566. SYS_MODE_FAULT = 12,
  7567. SYS_MODE_RESERVATION = 13,
  7568. SYS_MODE_BOOKING = 14,
  7569. SYS_MODE_MAINTAIN = 15,
  7570. SYS_MODE_DEBUG = 16,
  7571. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7572. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7573. SYS_MODE_UPDATE = 19
  7574. };
  7575. */
  7576. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7577. {
  7578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7579. goto end;
  7580. }
  7581. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7582. {
  7583. //check Transaction active
  7584. if(gunType[connectorIdInt -1] == 'J')
  7585. {
  7586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7587. {
  7588. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7589. }
  7590. else
  7591. {
  7592. tempIndex = connectorIdInt -1;
  7593. }
  7594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7595. {
  7596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7597. {
  7598. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7599. {
  7600. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7601. {
  7602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7603. {
  7604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7606. }
  7607. 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'))
  7608. {
  7609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7610. }
  7611. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7612. {
  7613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7614. }
  7615. else
  7616. {
  7617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7618. }
  7619. }
  7620. 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
  7621. {
  7622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7623. }
  7624. }
  7625. else
  7626. {
  7627. //replace reservation
  7628. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7630. }
  7631. }
  7632. } // END FOR CHAdeMO_QUANTITY
  7633. }
  7634. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7635. {
  7636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7637. {
  7638. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7639. }
  7640. else
  7641. {
  7642. tempIndex = connectorIdInt -1;
  7643. }
  7644. for (int index = 0; index < CCS_QUANTITY; index++)
  7645. {
  7646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7647. {
  7648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7649. {
  7650. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7651. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7652. {
  7653. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7654. {
  7655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7657. }
  7658. 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'))
  7659. {
  7660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7661. }
  7662. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7663. {
  7664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7665. }
  7666. else
  7667. {
  7668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7669. }
  7670. }
  7671. 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
  7672. {
  7673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7674. }
  7675. }
  7676. else
  7677. {
  7678. //replace reservation
  7679. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7681. }
  7682. }
  7683. } // END FOR CCS_QUANTITY
  7684. }
  7685. else if(gunType[connectorIdInt -1] == 'G')
  7686. {
  7687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7688. {
  7689. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7690. }
  7691. else
  7692. {
  7693. tempIndex = connectorIdInt -1;
  7694. }
  7695. for (int index = 0; index < GB_QUANTITY; index++)
  7696. {
  7697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7698. {
  7699. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7700. {
  7701. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7702. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7703. {
  7704. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7705. {
  7706. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7708. }
  7709. 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'))
  7710. {
  7711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7712. }
  7713. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7714. {
  7715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7716. }
  7717. else
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7720. }
  7721. }
  7722. 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
  7723. {
  7724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7725. }
  7726. }
  7727. else
  7728. {
  7729. //replace reservation
  7730. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7732. }
  7733. }
  7734. }// END FOR GB_QUANTITY
  7735. }
  7736. else
  7737. {
  7738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7739. {
  7740. tempIndex = 2;
  7741. }
  7742. else
  7743. {
  7744. tempIndex = (connectorIdInt -1);
  7745. }
  7746. for (int index = 0; index < AC_QUANTITY; index++)
  7747. {
  7748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7749. {
  7750. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7751. {
  7752. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7753. {
  7754. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7755. {
  7756. 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))
  7757. {
  7758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7759. }
  7760. else
  7761. {
  7762. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7764. }
  7765. }
  7766. 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'))
  7767. {
  7768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7769. }
  7770. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7771. {
  7772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7773. }
  7774. else
  7775. {
  7776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7777. }
  7778. }
  7779. 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
  7780. {
  7781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7782. }
  7783. }
  7784. else
  7785. {
  7786. //replace reservation
  7787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7789. }
  7790. }
  7791. } // END FOR AC_QUANTITY
  7792. }
  7793. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7794. }
  7795. else if(connectorIdInt == 0)
  7796. {
  7797. //check Transaction active
  7798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7799. {
  7800. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7801. {
  7802. 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'))
  7803. {
  7804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7805. goto end;
  7806. }
  7807. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7808. {
  7809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7810. goto end;
  7811. }
  7812. 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
  7813. {
  7814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7815. goto end;
  7816. }
  7817. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7818. {
  7819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7820. goto end;
  7821. }
  7822. }
  7823. }// END FOR CHAdeMO_QUANTITY
  7824. for (int index = 0; index < CCS_QUANTITY; index++)
  7825. {
  7826. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7827. {
  7828. 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'))
  7829. {
  7830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7831. goto end;
  7832. }
  7833. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7834. {
  7835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7836. goto end;
  7837. }
  7838. 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
  7839. {
  7840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7841. goto end;
  7842. }
  7843. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7844. {
  7845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7846. goto end;
  7847. }
  7848. }
  7849. } // END FOR CCS_QUANTITY
  7850. for (int index = 0; index < GB_QUANTITY; index++)
  7851. {
  7852. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7853. {
  7854. 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'))
  7855. {
  7856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7857. goto end;
  7858. }
  7859. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7860. {
  7861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7862. goto end;
  7863. }
  7864. 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
  7865. {
  7866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7867. goto end;
  7868. }
  7869. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7870. {
  7871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7872. goto end;
  7873. }
  7874. }
  7875. } // END FOR GB_QUANTITY
  7876. for (int index = 0; index < AC_QUANTITY; index++)
  7877. {
  7878. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7879. {
  7880. 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'))
  7881. {
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7883. goto end;
  7884. }
  7885. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7886. {
  7887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7888. goto end;
  7889. }
  7890. 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
  7891. {
  7892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7893. goto end;
  7894. }
  7895. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7896. {
  7897. 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))
  7898. {
  7899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7900. goto end;
  7901. }
  7902. }
  7903. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7904. {
  7905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7906. goto end;
  7907. }
  7908. }
  7909. }// END FOR AC_QUANTITY
  7910. //The connectorId is 0
  7911. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7913. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7914. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7915. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7916. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7917. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7918. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7919. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7920. result = TRUE;
  7921. return result;
  7922. }
  7923. else
  7924. {
  7925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7926. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7927. }
  7928. if(strcmp(comfirmstr,"Accepted") == 0)
  7929. {
  7930. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7931. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7933. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7934. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7935. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7936. result = TRUE;
  7937. return result;
  7938. }
  7939. end:
  7940. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7941. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7942. return result;
  7943. }
  7944. int handleResetRequest(char *uuid, char *payload)
  7945. {
  7946. mtrace();
  7947. int result = FAIL;
  7948. char sstr[10]={0},sstrtemp[30]={ 0 };
  7949. char typestr[10]={0};
  7950. char comfirmstr[20]={0};
  7951. int c = 0;
  7952. char *loc;
  7953. DEBUG_INFO("handleResetRequest...\n");
  7954. strcpy(sstrtemp, stringtrimspace(payload));
  7955. loc = strstr(sstrtemp, "type");
  7956. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7957. c = 0;
  7958. while (loc[3+strlen("type")+c] != '\"')
  7959. {
  7960. sstr[c] = loc[3+strlen("type")+c];
  7961. c++;
  7962. }
  7963. sstr[c] = '\0';
  7964. strcpy(typestr,sstr);
  7965. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7966. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7967. {
  7968. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7969. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7970. result = TRUE;
  7971. return result;
  7972. }
  7973. else
  7974. {
  7975. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7976. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7977. goto errorend;
  7978. }
  7979. errorend:
  7980. sendResetConfirmation(uuid, comfirmstr);
  7981. return result;
  7982. }
  7983. int handleSendLocalListRequest(char *uuid, char *payload)
  7984. {
  7985. mtrace();
  7986. int result = FAIL;
  7987. int listVersionInt;
  7988. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7989. char listsearch[]="listVersion";
  7990. char updateTypesearch[]="updateType";
  7991. char localAuthorizationListsearch[]="localAuthorizationList";
  7992. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7993. char CardList[500][160]={0};
  7994. char updateTypestr[15]={0};
  7995. char idTagstr[20]={0};
  7996. char parentIdTag[20]={0};
  7997. char expiryDate[30]={0};
  7998. char idTagstatus[16]={0};
  7999. int c = 0;
  8000. int i = 0;
  8001. char *delim1 = "}";
  8002. char * pch;
  8003. char *loc;
  8004. //char *ptr;
  8005. char comfirmstr[20];
  8006. //int n_localAuthorizations = 0;
  8007. int checkState_Faulted = FALSE;
  8008. DEBUG_INFO("handleSendLocalListRequest...\n");
  8009. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8010. {
  8011. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8012. goto end;
  8013. }
  8014. //check Charge Point state
  8015. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8016. {
  8017. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8018. {
  8019. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8020. }
  8021. }
  8022. for (int index = 0; index < CCS_QUANTITY; index++)
  8023. {
  8024. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8025. {
  8026. checkState_Faulted = TRUE; //OCPP Status
  8027. }
  8028. }
  8029. for (int index = 0; index < GB_QUANTITY; index++)
  8030. {
  8031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8032. {
  8033. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8034. }
  8035. }
  8036. //check Charge Point state
  8037. for (int index = 0; index < AC_QUANTITY; index++)
  8038. {
  8039. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8040. {
  8041. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8042. }
  8043. }
  8044. if(checkState_Faulted == TRUE)
  8045. {
  8046. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8047. goto end;
  8048. }
  8049. //Filter payload space
  8050. strcpy(sstrtemp, stringtrimspace(payload));
  8051. //listVersion
  8052. c = 0;
  8053. loc = strstr(sstrtemp, listsearch);
  8054. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8055. {
  8056. sstr[c] = loc[strlen("listVersion")+2+c];
  8057. c++;
  8058. }
  8059. sstr[c] = '\0';
  8060. listVersionInt = atoi(sstr);
  8061. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8062. //updateType
  8063. loc = strstr(sstrtemp, updateTypesearch);
  8064. c = 0;
  8065. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8066. {
  8067. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8068. c++;
  8069. }
  8070. sstr[c] = '\0';
  8071. strcpy(updateTypestr, sstr);
  8072. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8073. //localAuthorizationList
  8074. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8075. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8076. if(loc != NULL) // localAuthorizationList is not NULL
  8077. {
  8078. //Check UpdateType
  8079. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8080. {
  8081. //Local list full update
  8082. printf("Local list full update.\n");
  8083. OCPP_getListVerion();
  8084. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8085. {
  8086. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8087. goto end;
  8088. }
  8089. OCPP_cleanLocalList();
  8090. }
  8091. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8092. {
  8093. //Local list different update
  8094. printf("Local list different update.\n");
  8095. OCPP_getListVerion();
  8096. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8097. {
  8098. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8099. goto end;
  8100. }
  8101. }
  8102. else
  8103. {
  8104. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8105. goto end;
  8106. }
  8107. c = 0;
  8108. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8109. {
  8110. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8112. c++;
  8113. }
  8114. sstr[c] = '\0';
  8115. //DEBUG_INFO("sstr=%s\n", sstr);
  8116. //parsing strings to words
  8117. i = 0;
  8118. pch = strtok(sstr,delim1);
  8119. while (pch != NULL)
  8120. {
  8121. strcpy(CardList[i], pch);
  8122. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8123. pch = strtok (NULL, delim1);
  8124. i = i + 1;
  8125. }
  8126. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8127. //local Authorizations List Numbers
  8128. //n_localAuthorizations = i;
  8129. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8130. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8131. c= 0;
  8132. while(c < i) // i is CardList Number
  8133. {
  8134. //Search "IdToken"
  8135. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8136. loc = strstr(CardList[c], "idTag");
  8137. int j = 0;
  8138. while (loc[3+strlen("idTag")+j] != '\"')
  8139. {
  8140. sstr[j] = loc[3+strlen("idTag")+j];
  8141. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8142. j++;
  8143. }
  8144. sstr[j] = '\0';
  8145. strcpy(idTagstr, sstr);
  8146. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8147. //Search "expiryDate"
  8148. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8149. loc = strstr(CardList[c], "expiryDate");
  8150. j = 0;
  8151. if(loc != NULL)
  8152. {
  8153. while (loc[3+strlen("expiryDate")+j] != '\"')
  8154. {
  8155. sstr[j] = loc[3+strlen("expiryDate")+j];
  8156. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8157. j++;
  8158. }
  8159. sstr[j] = '\0';
  8160. strcpy(expiryDate, sstr);
  8161. }
  8162. else
  8163. {
  8164. strcpy(expiryDate, "");
  8165. }
  8166. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8167. //Search "parentIdTag"
  8168. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8169. loc = strstr(CardList[c], "parentIdTag");
  8170. j = 0;
  8171. if(loc != NULL)
  8172. {
  8173. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8174. {
  8175. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8176. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8177. j++;
  8178. }
  8179. sstr[j] = '\0';
  8180. strcpy(parentIdTag, sstr);
  8181. }
  8182. else
  8183. {
  8184. strcpy(parentIdTag, "");
  8185. }
  8186. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8187. //Search "status"
  8188. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8189. loc = strstr(CardList[c], "status");
  8190. j = 0;
  8191. while (loc[3+strlen("status")+j] != '\"')
  8192. {
  8193. sstr[j] = loc[3+strlen("status")+j];
  8194. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8195. j++;
  8196. }
  8197. sstr[j] = '\0';
  8198. strcpy(idTagstatus, sstr);
  8199. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8200. OCPP_getIdTag(idTagstr);
  8201. //OCPP_getIdTag("test"); For Test
  8202. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8203. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8204. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8205. {
  8206. //Local list full update
  8207. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8208. // update list
  8209. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8210. //DEBUG_INFO("Local list full update. 1\n");
  8211. //OCPP_get_TableAuthlocalAllData();
  8212. //DEBUG_INFO("Local list full update. 2\n");
  8213. }
  8214. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8215. {
  8216. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8217. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8218. }
  8219. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8220. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8221. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8222. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8223. c++;
  8224. }
  8225. }
  8226. else
  8227. {
  8228. //Check UpdateType
  8229. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8230. {
  8231. //Local list full update
  8232. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8233. OCPP_cleanLocalList();
  8234. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8235. goto end;
  8236. }
  8237. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8238. {
  8239. //Local list different update
  8240. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8241. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8242. goto end;
  8243. }
  8244. }
  8245. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8246. end:
  8247. sendSendLocalListConfirmation(uuid, comfirmstr);
  8248. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8249. return result;
  8250. }
  8251. #define MAX 200
  8252. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8253. {
  8254. mtrace();
  8255. int result = FAIL;
  8256. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8257. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8258. char chargingProfilePurposeStr[30]={0};
  8259. char chargingProfileKindStr[16]={0};
  8260. char recurrencyKindStr[10]={0};
  8261. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8262. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8263. int chargingSchedulePeriodCount = 0;
  8264. //int updateflag = FALSE;
  8265. char comfirmstr[20]={0};
  8266. int meet= FALSE;
  8267. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8268. int c = 0;
  8269. char *loc;
  8270. FILE *fptr1;//, *fptr2;
  8271. //int lno=0;//, linectr = 0;
  8272. //int modifyflag = FALSE;
  8273. char filename[MAX]={0};
  8274. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8275. //int resultRename=0;
  8276. char rmFileCmd[50]={0};
  8277. char tempchargingProfilePurposeStr[30]={0};
  8278. char word[1600]={0};
  8279. int n_chargingProfile = 0;
  8280. //[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}}}]
  8281. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8282. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8283. //Filter string space
  8284. strcpy(sstrtemp, stringtrimspace(payload));
  8285. //*********************connectorId***************************/
  8286. loc = strstr(sstrtemp, "connectorId");
  8287. c = 0;
  8288. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8289. while (loc[strlen("connectorId")+2+c] != ',')
  8290. {
  8291. sstr[c] = loc[strlen("connectorId")+2+c];
  8292. c++;
  8293. }
  8294. sstr[c] = '\0';
  8295. connectorIdInt = atoi(sstr);
  8296. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8297. {
  8298. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8299. }
  8300. else
  8301. {
  8302. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8303. }
  8304. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8305. //*********************chargingProfileId***************************/
  8306. loc = strstr(sstrtemp, "chargingProfileId");
  8307. c = 0;
  8308. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8309. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8310. {
  8311. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8312. c++;
  8313. }
  8314. sstr[c] = '\0';
  8315. chargingProfileIdInt = atoi(sstr);
  8316. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8317. {
  8318. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8319. }
  8320. else
  8321. {
  8322. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8323. }
  8324. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8325. //*********************transactionId***************************/
  8326. loc = strstr(sstrtemp, "transactionId");
  8327. if(loc != NULL)
  8328. {
  8329. c = 0;
  8330. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8331. while (loc[strlen("transactionId")+2+c] != ',')
  8332. {
  8333. sstr[c] = loc[strlen("transactionId")+2+c];
  8334. c++;
  8335. }
  8336. sstr[c] = '\0';
  8337. transactionIdInt = atoi(sstr);
  8338. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8339. {
  8340. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8341. }
  8342. else
  8343. {
  8344. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8345. }
  8346. }
  8347. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8348. //*********************stackLevel***************************/
  8349. loc = strstr(sstrtemp, "stackLevel");
  8350. c = 0;
  8351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8352. while (loc[strlen("stackLevel")+2+c] != ',')
  8353. {
  8354. sstr[c] = loc[strlen("stackLevel")+2+c];
  8355. c++;
  8356. }
  8357. sstr[c] = '\0';
  8358. stackLevelInt = atoi(sstr);
  8359. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8360. {
  8361. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8362. }
  8363. else
  8364. {
  8365. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8366. }
  8367. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8368. //*********************chargingProfilePurpose***************************/
  8369. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8370. c = 0;
  8371. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8372. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8373. {
  8374. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8376. c++;
  8377. }
  8378. sstr[c] = '\0';
  8379. strcpy(chargingProfilePurposeStr,sstr);
  8380. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8381. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8382. {
  8383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8384. }
  8385. else
  8386. {
  8387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8388. }
  8389. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8390. //*********************chargingProfileKind***************************/
  8391. loc = strstr(sstrtemp, "chargingProfileKind");
  8392. c = 0;
  8393. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8394. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8395. {
  8396. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8397. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8398. c++;
  8399. }
  8400. sstr[c] = '\0';
  8401. strcpy(chargingProfileKindStr,sstr);
  8402. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8403. {
  8404. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8405. }
  8406. else
  8407. {
  8408. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8409. }
  8410. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8411. //*********************recurrencyKind***************************/
  8412. loc = strstr(sstrtemp, "recurrencyKind");
  8413. if(loc != NULL)
  8414. {
  8415. c = 0;
  8416. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8417. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8418. {
  8419. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8420. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8421. c++;
  8422. }
  8423. sstr[c] = '\0';
  8424. strcpy(recurrencyKindStr,sstr);
  8425. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8426. {
  8427. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8428. }
  8429. else
  8430. {
  8431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8432. }
  8433. }
  8434. else
  8435. {
  8436. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8437. {
  8438. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8439. }
  8440. else
  8441. {
  8442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8443. }
  8444. }
  8445. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8446. //*********************validFrom***************************/
  8447. loc = strstr(sstrtemp, "validFrom");
  8448. if(loc != NULL)
  8449. {
  8450. c = 0;
  8451. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8452. while (loc[3+strlen("validFrom")+c] != '\"')
  8453. {
  8454. sstr[c] = loc[3+strlen("validFrom")+c];
  8455. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8456. c++;
  8457. }
  8458. sstr[c] = '\0';
  8459. strcpy(validFromStr,sstr);
  8460. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8461. {
  8462. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8463. }
  8464. else
  8465. {
  8466. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8467. }
  8468. }
  8469. else
  8470. {
  8471. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8472. {
  8473. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8474. }
  8475. else
  8476. {
  8477. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8478. }
  8479. }
  8480. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8481. //*********************validTo***************************/
  8482. loc = strstr(sstrtemp, "validTo");
  8483. if(loc != NULL)
  8484. {
  8485. c = 0;
  8486. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8487. while (loc[3+strlen("validTo")+c] != '\"')
  8488. {
  8489. sstr[c] = loc[3+strlen("validTo")+c];
  8490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8491. c++;
  8492. }
  8493. sstr[c] = '\0';
  8494. strcpy(validToStr,sstr);
  8495. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8496. {
  8497. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8498. }
  8499. else
  8500. {
  8501. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8502. }
  8503. }
  8504. else
  8505. {
  8506. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8507. {
  8508. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8509. }
  8510. else
  8511. {
  8512. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8513. }
  8514. }
  8515. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8516. //*********************duration***************************/
  8517. loc = strstr(sstrtemp, "duration");
  8518. if(loc != NULL)
  8519. {
  8520. c = 0;
  8521. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8522. while (loc[strlen("duration")+2+c] != ',')
  8523. {
  8524. sstr[c] = loc[strlen("duration")+2+c];
  8525. c++;
  8526. }
  8527. sstr[c] = '\0';
  8528. durationInt = atoi(sstr);
  8529. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8530. {
  8531. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8532. }
  8533. else
  8534. {
  8535. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8536. }
  8537. }
  8538. else
  8539. {
  8540. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8541. {
  8542. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8543. }
  8544. else
  8545. {
  8546. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8547. }
  8548. }
  8549. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8550. //*********************startSchedule***************************/
  8551. loc = strstr(sstrtemp, "startSchedule");
  8552. if(loc != NULL)
  8553. {
  8554. c = 0;
  8555. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8556. while (loc[3+strlen("startSchedule")+c] != '\"')
  8557. {
  8558. sstr[c] = loc[3+strlen("startSchedule")+c];
  8559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8560. c++;
  8561. }
  8562. sstr[c] = '\0';
  8563. strcpy(startScheduleStr,sstr);
  8564. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8565. {
  8566. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8567. }
  8568. else
  8569. {
  8570. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8571. }
  8572. }
  8573. else
  8574. {
  8575. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8576. {
  8577. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8578. }
  8579. else
  8580. {
  8581. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8582. }
  8583. }
  8584. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8585. //*********************chargingRateUnit***************************/
  8586. loc = strstr(sstrtemp, "chargingRateUnit");
  8587. if(loc != NULL)
  8588. {
  8589. c = 0;
  8590. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8591. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8592. {
  8593. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8594. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8595. c++;
  8596. }
  8597. sstr[c] = '\0';
  8598. strcpy(chargingRateUnitStr,sstr);
  8599. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8600. {
  8601. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8602. }
  8603. else
  8604. {
  8605. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8606. }
  8607. }
  8608. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8609. //****************chargingSchedulePeriod count start*******************/
  8610. int what_len = strlen("startPeriod");
  8611. char tempChargingProfile[1600]={0};
  8612. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8613. char *where = tempChargingProfile;
  8614. if (what_len)
  8615. {
  8616. while ((where = strstr(where, "startPeriod"))) {
  8617. where += what_len;
  8618. chargingSchedulePeriodCount++;
  8619. }
  8620. }
  8621. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8622. {
  8623. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8624. goto end;
  8625. }
  8626. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8627. //where = payload;
  8628. int templength = 0;
  8629. //int searchstart = 0;
  8630. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8631. {
  8632. //****************startPeriod*******************/
  8633. c=0;
  8634. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8635. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8636. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8637. {
  8638. sstr[c] = loc[strlen("startPeriod")+2+c];
  8639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8640. c++;
  8641. }
  8642. sstr[c] = '\0';
  8643. startPeriodInt[periodNums] = atoi(sstr);
  8644. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8645. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8646. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8649. }
  8650. else
  8651. {
  8652. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8653. }
  8654. templength = strlen("startPeriod")+2+c;
  8655. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8656. //****************limit*******************/
  8657. c=0;
  8658. loc = strstr(tempChargingProfile + templength, "limit");
  8659. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8660. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8661. {
  8662. sstr[c] = loc[strlen("limit")+2+c];
  8663. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8664. c++;
  8665. }
  8666. sstr[c] = '\0';
  8667. limitflaot[periodNums] = atof(sstr);
  8668. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8669. {
  8670. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8671. }
  8672. else
  8673. {
  8674. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8675. }
  8676. templength = templength + strlen("limit")+2+c;
  8677. //****************numberPhases*******************/
  8678. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8679. if(loc != NULL)
  8680. {
  8681. c=0;
  8682. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8683. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8684. {
  8685. sstr[c] = loc[strlen("numberPhases")+2+c];
  8686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8687. c++;
  8688. }
  8689. sstr[c] = '\0';
  8690. numberPhasesInt[periodNums] = atoi(sstr);
  8691. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8692. {
  8693. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8694. }
  8695. else
  8696. {
  8697. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8698. }
  8699. templength = templength + strlen("numberPhases")+2+c;
  8700. }
  8701. //where = loc;
  8702. }
  8703. //****************chargingSchedulePeriod count end*******************/
  8704. //*********************minChargingRate***************************/
  8705. loc = strstr(sstrtemp, "minChargingRate");
  8706. if(loc != NULL)
  8707. {
  8708. c = 0;
  8709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8710. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8711. {
  8712. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8713. c++;
  8714. }
  8715. sstr[c] = '\0';
  8716. minChargingRateFloat = atof(sstr);
  8717. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8718. {
  8719. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8720. }
  8721. else
  8722. {
  8723. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8724. }
  8725. }
  8726. else
  8727. {
  8728. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8729. {
  8730. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8731. }
  8732. else
  8733. {
  8734. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8735. }
  8736. }
  8737. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8738. {
  8739. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8740. if(connectorIdInt != 0)
  8741. {
  8742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8743. goto end;
  8744. }
  8745. strcpy(filename, ChargePointMaxProfile_JSON );
  8746. fptr1 = fopen(filename, "r");
  8747. if (!fptr1)
  8748. {
  8749. //file not exist
  8750. DEBUG_INFO("Unable to open the input file!!\n");
  8751. fptr1 = fopen(filename, "w+");
  8752. }
  8753. else
  8754. {
  8755. //Check Charging Profile Count
  8756. while(fscanf(fptr1, "%s", word) != EOF)
  8757. {
  8758. //DEBUG_INFO("word=%s\n",word);
  8759. if(strstr(word, "chargingProfileId")!= NULL)
  8760. {
  8761. //DEBUG_INFO("test chargingProfileId \n");
  8762. n_chargingProfile = n_chargingProfile + 1;
  8763. //DEBUG_INFO("chargingProfileId Found\n");
  8764. }
  8765. }
  8766. }
  8767. fclose(fptr1);
  8768. }
  8769. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8770. {
  8771. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8772. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8773. {
  8774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8775. goto end;
  8776. }
  8777. memset(filename, 0, ARRAY_SIZE(filename));
  8778. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8779. fptr1 = fopen(filename, "r");
  8780. if (!fptr1)
  8781. {
  8782. //file not exist
  8783. //DEBUG_INFO("Unable to open the input file!!\n");
  8784. fptr1 = fopen(filename, "w+");
  8785. }
  8786. else
  8787. {
  8788. //Check Charging Profile Count
  8789. while(fscanf(fptr1, "%s", word) != EOF)
  8790. {
  8791. //DEBUG_INFO("word=%s\n",word);
  8792. if(strstr(word, "chargingProfileId")!= NULL)
  8793. {
  8794. //DEBUG_INFO("test chargingProfileId \n");
  8795. n_chargingProfile = n_chargingProfile + 1;
  8796. //DEBUG_INFO("chargingProfileId Found\n");
  8797. }
  8798. }
  8799. }
  8800. fclose(fptr1);
  8801. }
  8802. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8803. {
  8804. //printf("set chargingProfile 1-4\n");
  8805. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8806. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8807. if(connectorIdInt == 0)
  8808. {
  8809. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8810. goto end;
  8811. }
  8812. int tempIndex = 0;
  8813. //check Transaction active
  8814. if(gunType[connectorIdInt -1] == 'J')
  8815. {
  8816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8817. {
  8818. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8819. }
  8820. else
  8821. {
  8822. tempIndex = connectorIdInt -1;
  8823. }
  8824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8825. {
  8826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8827. {
  8828. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8829. {
  8830. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8831. {
  8832. meet = TRUE;
  8833. break;
  8834. }
  8835. }
  8836. }
  8837. }
  8838. }
  8839. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8840. {
  8841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8842. {
  8843. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8844. }
  8845. else
  8846. {
  8847. tempIndex = connectorIdInt -1;
  8848. }
  8849. for (int index = 0; index < CCS_QUANTITY; index++)
  8850. {
  8851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8852. {
  8853. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8854. {
  8855. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8856. {
  8857. meet = TRUE;
  8858. break;
  8859. }
  8860. }
  8861. }
  8862. }
  8863. }
  8864. else if(gunType[connectorIdInt -1] == 'G')
  8865. {
  8866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8867. {
  8868. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8869. }
  8870. else
  8871. {
  8872. tempIndex = connectorIdInt -1;
  8873. }
  8874. for (int index = 0; index < GB_QUANTITY; index++)
  8875. {
  8876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8877. {
  8878. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8879. {
  8880. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8881. {
  8882. meet = TRUE;
  8883. break;
  8884. }
  8885. }
  8886. }
  8887. }
  8888. }
  8889. else
  8890. {
  8891. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8892. {
  8893. tempIndex = 2;
  8894. }
  8895. else
  8896. {
  8897. tempIndex = (connectorIdInt -1);
  8898. }
  8899. for (int index = 0; index < AC_QUANTITY; index++)
  8900. {
  8901. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8902. {
  8903. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8904. {
  8905. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8906. {
  8907. meet = TRUE;
  8908. break;
  8909. }
  8910. }
  8911. }
  8912. }
  8913. }
  8914. //check Transaction active
  8915. if(meet == FALSE)
  8916. {
  8917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8918. goto end;
  8919. }
  8920. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8921. {
  8922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8923. goto end;
  8924. }
  8925. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8926. fptr1 = fopen(filename, "r");
  8927. if (!fptr1)
  8928. {
  8929. //file not exist
  8930. DEBUG_INFO("Unable to open the input file!!\n");
  8931. fptr1 = fopen(filename, "w+");
  8932. }
  8933. else
  8934. {
  8935. //Check Charging Profile Count
  8936. while(fscanf(fptr1, "%s", word) != EOF)
  8937. {
  8938. //DEBUG_INFO("word=%s\n",word);
  8939. if(strstr(word, "chargingProfileId")!= NULL)
  8940. {
  8941. //DEBUG_INFO("test chargingProfileId \n");
  8942. n_chargingProfile = n_chargingProfile + 1;
  8943. //DEBUG_INFO("chargingProfileId Found\n");
  8944. }
  8945. }
  8946. }
  8947. fclose(fptr1);
  8948. }
  8949. // Check ChargeProfileMaxStackLevel
  8950. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8951. {
  8952. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8953. goto end;
  8954. }
  8955. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8956. {
  8957. int i = 0;
  8958. char fnametemp[200]={0};
  8959. n_chargingProfile = 0;
  8960. //Check ChargePointMaxProfile.json exit
  8961. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8962. {
  8963. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8964. //Check Charging Profile Count
  8965. while(fscanf(fptr1, "%s", word) != EOF)
  8966. {
  8967. //DEBUG_INFO("word=%s\n",word);
  8968. if(strstr(word, "chargingProfileId")!= NULL)
  8969. {
  8970. //DEBUG_INFO("test chargingProfileId \n");
  8971. n_chargingProfile = n_chargingProfile + 1;
  8972. i = i + 1;
  8973. //DEBUG_INFO("chargingProfileId Found\n");
  8974. }
  8975. memset(word, 0, ARRAY_SIZE(word));
  8976. }
  8977. fclose(fptr1);
  8978. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8979. }
  8980. //Check TxDefaultProfile_0.json exit
  8981. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8982. {
  8983. i = 0;
  8984. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8985. //Check Charging Profile Count
  8986. while(fscanf(fptr1, "%s", word) != EOF)
  8987. {
  8988. //DEBUG_INFO("word=%s\n",word);
  8989. if(strstr(word, "chargingProfileId")!= NULL)
  8990. {
  8991. //DEBUG_INFO("test chargingProfileId \n");
  8992. n_chargingProfile = n_chargingProfile + 1;
  8993. i = i + 1;
  8994. //DEBUG_INFO("chargingProfileId Found\n");
  8995. }
  8996. memset(word, 0, ARRAY_SIZE(word));
  8997. }
  8998. fclose(fptr1);
  8999. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9000. }
  9001. //Check TxDefaultProfile_%d.json
  9002. for(int j=1; j <= gunTotalNumber; j++)
  9003. {
  9004. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9005. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9006. if((access(fnametemp,F_OK))!=-1)
  9007. {
  9008. i = 0;
  9009. fptr1 = fopen(fnametemp, "r");
  9010. //Check Charging Profile Count
  9011. while(fscanf(fptr1, "%s", word) != EOF)
  9012. {
  9013. //DEBUG_INFO("word=%s\n",word);
  9014. if(strstr(word, "chargingProfileId")!= NULL)
  9015. {
  9016. //DEBUG_INFO("test chargingProfileId \n");
  9017. n_chargingProfile = n_chargingProfile + 1;
  9018. i = i + 1;
  9019. //DEBUG_INFO("chargingProfileId Found\n");
  9020. }
  9021. memset(word, 0, ARRAY_SIZE(word));
  9022. }
  9023. fclose(fptr1);
  9024. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9025. }
  9026. }
  9027. //Check TxProfile_%d.json
  9028. for(int j=1; j <= gunTotalNumber; j++)
  9029. {
  9030. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9031. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9032. if((access(fnametemp,F_OK))!=-1)
  9033. {
  9034. i = 0;
  9035. fptr1 = fopen(fnametemp, "r");
  9036. //Check Charging Profile Count
  9037. while(fscanf(fptr1, "%s", word) != EOF)
  9038. {
  9039. //DEBUG_INFO("word=%s\n",word);
  9040. if(strstr(word, "chargingProfileId")!= NULL)
  9041. {
  9042. //DEBUG_INFO("test chargingProfileId \n");
  9043. n_chargingProfile = n_chargingProfile + 1;
  9044. i = i + 1;
  9045. //DEBUG_INFO("chargingProfileId Found\n");
  9046. }
  9047. memset(word, 0, ARRAY_SIZE(word));
  9048. }
  9049. fclose(fptr1);
  9050. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9051. }
  9052. }
  9053. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9054. {
  9055. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9056. goto end;
  9057. }
  9058. }
  9059. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9060. //**********************************Write to File********************************************************/
  9061. FILE *infile;
  9062. FILE *outfile;
  9063. // open file for writing
  9064. infile = fopen (filename, "r");
  9065. outfile = fopen (tempfile, "w");
  9066. int d =0;
  9067. d = fgetc(infile);
  9068. //DEBUG_INFO("d:%d\n",d);
  9069. rewind(infile);
  9070. //*璉 瘚 辣蝏     1嚗   0 */
  9071. if(d == EOF)
  9072. {
  9073. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9074. fprintf(outfile,"%s\n",payload);
  9075. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9076. fclose(infile);
  9077. fclose(outfile);
  9078. sprintf(rmFileCmd,"rm -f %s",filename);
  9079. system(rmFileCmd);
  9080. rename(tempfile, filename);
  9081. sleep(1);
  9082. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9083. //system(rmFileCmd);
  9084. }
  9085. else
  9086. {
  9087. char buf[1000]={0};
  9088. int ChargingProfileAdded = FALSE;
  9089. while (fgets(buf, sizeof(buf), infile) != NULL)
  9090. {
  9091. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9092. //*************************tempconnectorIdInt*********************************/
  9093. loc = strstr(buf, "connectorId");
  9094. c = 0;
  9095. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9096. while (loc[strlen("connectorId")+2+c] != ',')
  9097. {
  9098. sstr[c] = loc[strlen("connectorId")+2+c];
  9099. c++;
  9100. }
  9101. sstr[c] = '\0';
  9102. tempconnectorIdInt = atoi(sstr);
  9103. //*************************tempchargingProfileIdInt*********************************/
  9104. loc = strstr(buf, "chargingProfileId");
  9105. c = 0;
  9106. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9107. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9108. {
  9109. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9110. c++;
  9111. }
  9112. sstr[c] = '\0';
  9113. tempchargingProfileIdInt = atoi(sstr);
  9114. //*************************tempstackLevelInt*********************************/
  9115. loc = strstr(buf, "stackLevel");
  9116. c = 0;
  9117. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9118. while (loc[strlen("stackLevel")+2+c] != ',')
  9119. {
  9120. sstr[c] = loc[strlen("stackLevel")+2+c];
  9121. c++;
  9122. }
  9123. sstr[c] = '\0';
  9124. tempstackLevelInt = atoi(sstr);
  9125. //*************************tempchargingProfilePurposeStr*********************************/
  9126. loc = strstr(payload, "chargingProfilePurpose");
  9127. c = 0;
  9128. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9129. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9130. {
  9131. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9133. c++;
  9134. }
  9135. sstr[c] = '\0';
  9136. strcpy(tempchargingProfilePurposeStr,sstr);
  9137. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9138. {
  9139. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9140. {
  9141. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9142. if(ChargingProfileAdded == FALSE)
  9143. {
  9144. fprintf(outfile,"%s\n",payload);
  9145. ChargingProfileAdded = TRUE;
  9146. }
  9147. }
  9148. else
  9149. {
  9150. if(tempstackLevelInt < stackLevelInt)
  9151. {
  9152. if(ChargingProfileAdded == FALSE)
  9153. {
  9154. fprintf(outfile,"%s\n",payload);
  9155. ChargingProfileAdded = TRUE;
  9156. fprintf(outfile,"%s\n",buf);
  9157. }
  9158. else
  9159. {
  9160. fprintf(outfile,"%s\n",buf);
  9161. }
  9162. }
  9163. else
  9164. {
  9165. if(ChargingProfileAdded == FALSE)
  9166. {
  9167. fprintf(outfile,"%s\n",buf);
  9168. fprintf(outfile,"%s\n",payload);
  9169. ChargingProfileAdded = TRUE;
  9170. }
  9171. else
  9172. {
  9173. fprintf(outfile,"%s\n",buf);
  9174. }
  9175. }
  9176. }
  9177. }
  9178. else
  9179. {
  9180. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9181. {
  9182. if(ChargingProfileAdded == FALSE)
  9183. {
  9184. fprintf(outfile,"%s\n",payload);
  9185. ChargingProfileAdded = TRUE;
  9186. fprintf(outfile,"%s\n",buf);
  9187. }
  9188. else
  9189. {
  9190. fprintf(outfile,"%s\n",buf);
  9191. }
  9192. }
  9193. else if(tempstackLevelInt < stackLevelInt)
  9194. {
  9195. if(ChargingProfileAdded == FALSE)
  9196. {
  9197. fprintf(outfile,"%s\n",payload);
  9198. ChargingProfileAdded = TRUE;
  9199. fprintf(outfile,"%s\n",buf);
  9200. }
  9201. else
  9202. {
  9203. fprintf(outfile,"%s\n",buf);
  9204. }
  9205. }
  9206. else
  9207. {
  9208. if(ChargingProfileAdded == FALSE)
  9209. {
  9210. fprintf(outfile,"%s\n",buf);
  9211. fprintf(outfile,"%s\n",payload);
  9212. ChargingProfileAdded = TRUE;
  9213. }
  9214. else
  9215. {
  9216. fprintf(outfile,"%s\n",buf);
  9217. }
  9218. }
  9219. }
  9220. } // end of while loop
  9221. fclose(infile);
  9222. fclose(outfile);
  9223. sprintf(rmFileCmd,"rm -f %s",filename);
  9224. system(rmFileCmd);
  9225. rename(tempfile, filename);
  9226. sleep(1);
  9227. result = TRUE;
  9228. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9229. }
  9230. end:
  9231. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9232. return result;
  9233. return result;
  9234. }
  9235. int handleTriggerMessageRequest(char *uuid, char *payload)
  9236. {
  9237. mtrace();
  9238. int result = FAIL;
  9239. int connectorIdIsNULL = FALSE;
  9240. int connectorIdInt =0;
  9241. char sstr[40]={0},sstrtemp[100]={ 0 };
  9242. char requestedMessagestr[40]={0};
  9243. char comfirmstr[20]={0};
  9244. int c = 0;
  9245. char *loc;
  9246. DEBUG_INFO("handleTriggerMessageRequest\n");
  9247. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9248. strcpy(sstrtemp, stringtrimspace(payload));
  9249. c = 0;
  9250. loc = strstr(sstrtemp, "requestedMessage");
  9251. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9252. {
  9253. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9254. c++;
  9255. }
  9256. sstr[c] = '\0';
  9257. strcpy(requestedMessagestr, sstr);
  9258. c = 0;
  9259. loc = strstr(sstrtemp, "connectorId");
  9260. if(loc == NULL)
  9261. {
  9262. connectorIdIsNULL = TRUE;
  9263. }
  9264. else
  9265. {
  9266. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9267. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9268. {
  9269. sstr[c] = loc[strlen("connectorId")+2+c];
  9270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9271. c++;
  9272. }
  9273. sstr[c] = '\0';
  9274. connectorIdInt = atoi(sstr);
  9275. }
  9276. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9277. {
  9278. //connectorIdInt = json_object_get_int(connectorId);
  9279. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9280. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9281. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9282. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9283. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9284. }
  9285. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9286. {
  9287. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9288. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9289. return TRUE;
  9290. }
  9291. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9292. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9293. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9294. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9295. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9296. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9297. {
  9298. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9299. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9300. return TRUE;
  9301. }
  9302. else
  9303. {
  9304. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9305. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9306. }
  9307. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9308. {
  9309. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9310. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9311. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9312. {
  9313. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9314. }
  9315. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9316. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9317. }
  9318. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9319. {
  9320. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9321. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9322. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9323. }
  9324. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9325. {
  9326. sendBootNotificationRequest();
  9327. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9328. }
  9329. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9330. {
  9331. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9332. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9333. }
  9334. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9335. {
  9336. if(connectorIdIsNULL == FALSE)
  9337. {
  9338. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9339. {
  9340. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9341. sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9342. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9343. }
  9344. }
  9345. else
  9346. {
  9347. for(int idx=0;idx< gunTotalNumber;idx++)
  9348. {
  9349. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9350. sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9351. }
  9352. }
  9353. }
  9354. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9355. {
  9356. if(connectorIdIsNULL == FALSE)
  9357. {
  9358. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9359. {
  9360. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9361. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9362. }
  9363. }
  9364. else
  9365. {
  9366. for(int idx=0;idx< gunTotalNumber;idx++)
  9367. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9368. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9369. }
  9370. }
  9371. return result;
  9372. }
  9373. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9374. {
  9375. mtrace();
  9376. int result = FAIL;
  9377. char sstr[6]={0},sstrtemp[50]={ 0 };
  9378. int connectorIdInt =0;
  9379. char comfirmstr[20]={0};
  9380. int c = 0;
  9381. int tempIndex = 0;
  9382. char *loc;
  9383. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9384. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9385. strcpy(sstrtemp, stringtrimspace(payload));
  9386. c = 0;
  9387. loc = strstr(sstrtemp, "connectorId");
  9388. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9389. while (loc[strlen("connectorId")+2+c] != '}')
  9390. {
  9391. sstr[c] = loc[strlen("connectorId")+2+c];
  9392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9393. c++;
  9394. }
  9395. sstr[c] = '\0';
  9396. connectorIdInt = atoi(sstr);
  9397. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9398. if(gunTotalNumber == 0)
  9399. {
  9400. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9401. goto end;
  9402. }
  9403. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9404. {
  9405. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9406. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9407. goto end;
  9408. }
  9409. else
  9410. {
  9411. //check Transaction active
  9412. if(gunType[connectorIdInt-1] == 'J')
  9413. {
  9414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9415. {
  9416. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9417. }
  9418. else
  9419. {
  9420. tempIndex = connectorIdInt -1;
  9421. }
  9422. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9423. {
  9424. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9425. {
  9426. //stop Transaction
  9427. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9428. }
  9429. }
  9430. }
  9431. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9432. {
  9433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9434. {
  9435. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9436. }
  9437. else
  9438. {
  9439. tempIndex = connectorIdInt -1;
  9440. }
  9441. for (int index = 0; index < CCS_QUANTITY; index++)
  9442. {
  9443. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9444. {
  9445. //stop Transaction
  9446. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9447. }
  9448. }
  9449. }
  9450. else if(gunType[connectorIdInt-1] == 'G')
  9451. {
  9452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9453. {
  9454. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9455. }
  9456. else
  9457. {
  9458. tempIndex = connectorIdInt -1;
  9459. }
  9460. for (int index = 0; index < GB_QUANTITY; index++)
  9461. {
  9462. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9463. {
  9464. //stop Transaction
  9465. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9466. }
  9467. }
  9468. }
  9469. else
  9470. {
  9471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9472. {
  9473. tempIndex = 2;
  9474. }
  9475. else
  9476. {
  9477. tempIndex = connectorIdInt-1;
  9478. }
  9479. for (int index = 0; index < AC_QUANTITY; index++)
  9480. {
  9481. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9482. {
  9483. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9484. }
  9485. }
  9486. }
  9487. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9488. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9489. result = TRUE;
  9490. return result;
  9491. }
  9492. end:
  9493. //json_object_put(obj); --- remove temporally
  9494. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9495. return result;
  9496. }
  9497. static char UpdateFirmwarepayloadData[300]={0};
  9498. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9499. {
  9500. mtrace();
  9501. int result = FAIL;
  9502. pthread_t t;
  9503. sendUpdateFirmwareConfirmation(uuid);
  9504. memset(UpdateFirmwarepayloadData, 0, 300);
  9505. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9506. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9507. ////pthread_join(t, NULL); //
  9508. //pthread_detach(t);
  9509. //sendUpdateFirmwareConfirmation(uuid);
  9510. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9511. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9512. return result;
  9513. }
  9514. void *UpdateFirmwareProcess(void *data)
  9515. {
  9516. pthread_detach(pthread_self());
  9517. mtrace();
  9518. int retriesInt =0, retryIntervalInt=0;
  9519. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9520. int port=0;
  9521. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9522. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9523. //char comfirmstr[20];
  9524. int isSuccess = 0;
  9525. char ftpbuf[200];
  9526. char temp[100];
  9527. char * pch;
  9528. int retriesISNULL=FALSE;
  9529. int retryInterval=FALSE;
  9530. int c = 0;
  9531. //int i = 0;
  9532. char *loc;
  9533. char sstr[300]={ 0 };
  9534. char str[300]={ 0 };
  9535. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9536. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9537. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9538. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9539. //***************location **************/
  9540. loc = strstr(str, "location");
  9541. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9542. c = 0;
  9543. while (loc[3+strlen("location")+c] != '\"')
  9544. {
  9545. sstr[c] = loc[3+strlen("location")+c];
  9546. c++;
  9547. }
  9548. sstr[c] = '\0';
  9549. strcpy(locationstr, sstr);
  9550. //***************retries**************/
  9551. c = 0;
  9552. loc = strstr(str, "retries");
  9553. if(loc == NULL)
  9554. {
  9555. retriesISNULL=TRUE;
  9556. }
  9557. else
  9558. {
  9559. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9560. while (loc[strlen("retries")+2+c] != ',')
  9561. {
  9562. sstr[c] = loc[strlen("retries")+2+c];
  9563. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9564. c++;
  9565. }
  9566. sstr[c] = '\0';
  9567. }
  9568. if(retriesISNULL == FALSE)
  9569. {
  9570. retriesInt = atoi(sstr);
  9571. }
  9572. //***************retrieveDate **************/
  9573. loc = strstr(str, "retrieveDate");
  9574. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9575. c = 0;
  9576. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9577. {
  9578. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9579. c++;
  9580. }
  9581. sstr[c] = '\0';
  9582. strcpy(retrieveDatestr, sstr);
  9583. //***************retryInterval **************/
  9584. c = 0;
  9585. loc = strstr(str, "retryInterval");
  9586. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9587. if(loc == NULL)
  9588. {
  9589. retryInterval=TRUE;
  9590. }
  9591. else
  9592. {
  9593. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9594. {
  9595. sstr[c] = loc[strlen("retryInterval")+2+c];
  9596. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9597. c++;
  9598. }
  9599. sstr[c] = '\0';
  9600. }
  9601. if(retryInterval==FALSE)
  9602. {
  9603. retryIntervalInt = atoi(sstr);
  9604. }
  9605. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9606. memset(path, 0, ARRAY_SIZE(path));
  9607. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9608. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9609. if(strncmp(locationstr,"http", 4) == 0)
  9610. {
  9611. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9612. protocol, host, path);
  9613. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9614. // protocol, user, password, host, path);
  9615. sprintf(ftppath,"/%s", path);
  9616. //DEBUG_INFO("protocol =%s\n",protocol);
  9617. //DEBUG_INFO("host =%s\n",host);
  9618. //DEBUG_INFO("path =%s\n",path);
  9619. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9620. int ftppathlen=strlen(ftppath);
  9621. int i=1;
  9622. char filenametemp[50];
  9623. while(i < ftppathlen)
  9624. {
  9625. int len=ftppathlen-i;
  9626. if(ftppath[len]== 47) // '/' ascll code: 47
  9627. {
  9628. DEBUG_INFO("compare '/' all right\n");
  9629. break;
  9630. }
  9631. i=i+1;
  9632. }
  9633. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9634. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9635. filenametemp[i+1] = 0;
  9636. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9637. do{
  9638. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9639. sleep(retryIntervalInt);
  9640. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9641. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9642. if(!isSuccess)
  9643. {
  9644. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9645. }
  9646. else
  9647. {
  9648. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9649. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9650. //isUpdateRequest = TRUE;
  9651. }
  9652. }
  9653. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9654. {
  9655. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9656. memset(temp, 0, ARRAY_SIZE(temp));
  9657. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9658. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9659. int ftppathlen=strlen(ftpbuf);
  9660. int i=1;
  9661. char filenametemp[50];
  9662. while(i < ftppathlen)
  9663. {
  9664. int len=ftppathlen-i;
  9665. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9666. {
  9667. DEBUG_INFO(" compare '/' all right\n");
  9668. break;
  9669. }
  9670. i=i+1;
  9671. }
  9672. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9673. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9674. filenametemp[i+1] = 0;
  9675. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9676. pch=strchr(temp,'@');
  9677. if(pch==NULL)
  9678. {
  9679. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9680. protocol, host, &port, path);
  9681. strcpy(user,"anonymous");
  9682. strcpy(password,"");
  9683. }
  9684. else
  9685. {
  9686. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9687. protocol, user, password, host, &port, path);
  9688. }
  9689. sscanf(host,"%[^/]%s",host1, path1);
  9690. sprintf(ftppath,"%s", path1);
  9691. //DEBUG_INFO("protocol =%s\n",protocol);
  9692. //DEBUG_INFO("user =%s\n",user);
  9693. //DEBUG_INFO("password =%s\n",password);
  9694. //DEBUG_INFO("host1 =%s\n",host1);
  9695. //DEBUG_INFO("port =%d\n",port);
  9696. //DEBUG_INFO("path1 =%s\n",path1);
  9697. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9698. //ftpFile(host, user, password, port, ftppath, fname);
  9699. //download firmware pthred
  9700. if(port == 0)
  9701. {
  9702. port = 21;
  9703. }
  9704. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9705. do{
  9706. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9707. sleep(retryIntervalInt);
  9708. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9709. if(!isSuccess)
  9710. {
  9711. //BulldogUtil.sleepMs(interval*1000);
  9712. DEBUG_INFO("Update firmware request and download file fail.\n");
  9713. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9714. }
  9715. else
  9716. {
  9717. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9718. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9719. //isUpdateRequest = TRUE;
  9720. }
  9721. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9722. }
  9723. else
  9724. {
  9725. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9726. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9727. }
  9728. pthread_exit(NULL);
  9729. }
  9730. //==========================================
  9731. // Handle server response routine
  9732. //==========================================
  9733. void handleAuthorizeResponse(char *payload, int gun_index)
  9734. {
  9735. mtrace();
  9736. char expiryDatestr[30]={0};
  9737. char parentIdTagstr[20]={0};
  9738. char statusstr[20]={0};
  9739. char expiryDatestrtemp[30]={0};
  9740. char parentIdTagstrtemp[20]={0};
  9741. char IdTagstrtemp[20]={0};
  9742. char statusstrtemp[20]={0};
  9743. int expiryDateISNULL=FALSE;
  9744. int parentIdTagISNULL=FALSE;
  9745. char sstr[160]={0};
  9746. char* filename = AuthorizationCache_JSON;
  9747. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9748. char *loc;
  9749. int resultRename=0;
  9750. int responseIdTagInfoAsZero= 0;
  9751. char rmFileCmd[50]={0};
  9752. DEBUG_INFO("handleAuthorizeResponse...\n");
  9753. json_object *Authorize;
  9754. Authorize = json_tokener_parse(payload);
  9755. if(!is_error(Authorize))
  9756. {
  9757. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9758. {
  9759. // Required data
  9760. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9761. // Optional data
  9762. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9763. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9764. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9765. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9766. }
  9767. }
  9768. json_object_put(Authorize);
  9769. if(expiryDateISNULL == FALSE)
  9770. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9771. if(parentIdTagISNULL == FALSE)
  9772. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9773. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9774. //Update idTag information to authorization cache if supproted
  9775. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9776. {
  9777. if((access(filename,F_OK))!=-1)
  9778. {
  9779. printf("AuthorizationCache exist.\n");
  9780. }
  9781. else
  9782. {
  9783. printf("AuthorizationCache not exist\n");
  9784. FILE *log = fopen(filename, "w+");
  9785. if(log == NULL)
  9786. {
  9787. printf("log is NULL\n");
  9788. goto out;
  9789. }
  9790. else
  9791. {
  9792. fclose(log);
  9793. }
  9794. }
  9795. FILE *infile;
  9796. FILE *outfile;
  9797. // open file for writing
  9798. infile = fopen (filename, "r");
  9799. outfile = fopen (tempfile, "w");
  9800. int c;
  9801. c = fgetc(infile);
  9802. //DEBUG_INFO("c:%d\n",c);
  9803. rewind(infile);
  9804. if(c == EOF)
  9805. {
  9806. DEBUG_INFO("Orignal File is NULL\n");
  9807. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9808. {
  9809. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9810. }
  9811. else
  9812. {
  9813. strcpy(expiryDatestrtemp, "");
  9814. }
  9815. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9816. {
  9817. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9818. }
  9819. else
  9820. {
  9821. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9822. }
  9823. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9824. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9825. fclose(infile);
  9826. fclose(outfile);
  9827. sprintf(rmFileCmd,"rm -f %s",filename);
  9828. system(rmFileCmd);
  9829. resultRename = rename(tempfile, filename);
  9830. if(resultRename == 0)
  9831. {
  9832. printf("File renamed successfully");
  9833. }
  9834. else
  9835. {
  9836. printf("Error: unable to rename the file");
  9837. }
  9838. }
  9839. else
  9840. {
  9841. char buf[160]={0};
  9842. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9843. {
  9844. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9845. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9846. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9847. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9848. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9849. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9850. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9851. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9852. //------------------IdTag-----------------------
  9853. loc = strstr(buf, "idTag");
  9854. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9855. c = 0;
  9856. while (loc[3+strlen("idTag")+c] != '\"')
  9857. {
  9858. sstr[c] = loc[3+strlen("idTag")+c];
  9859. c++;
  9860. }
  9861. sstr[c] = '\0';
  9862. strcpy(IdTagstrtemp,sstr);
  9863. //*********************expiryDate***************/
  9864. loc = strstr(buf, "expiryDate");
  9865. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9866. c = 0;
  9867. while (loc[3+strlen("expiryDate")+c] != '\"')
  9868. {
  9869. sstr[c] = loc[3+strlen("expiryDate")+c];
  9870. c++;
  9871. }
  9872. sstr[c] = '\0';
  9873. strcpy(expiryDatestr,sstr);
  9874. //*********************parentIdTag***************/
  9875. loc = strstr(buf, "parentIdTag");
  9876. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9877. c = 0;
  9878. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9879. {
  9880. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9881. c++;
  9882. }
  9883. sstr[c] = '\0';
  9884. strcpy(parentIdTagstr,sstr);
  9885. //*********************status***************/
  9886. loc = strstr(buf, "status");
  9887. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9888. c = 0;
  9889. while (loc[3+strlen("status")+c] != '\"')
  9890. {
  9891. sstr[c] = loc[3+strlen("status")+c];
  9892. c++;
  9893. }
  9894. sstr[c] = '\0';
  9895. strcpy(statusstr,sstr);
  9896. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9897. {
  9898. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9899. responseIdTagInfoAsZero = 1;
  9900. }
  9901. else
  9902. {
  9903. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9904. }
  9905. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9906. {
  9907. //modify item
  9908. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9909. {
  9910. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9911. }
  9912. else
  9913. {
  9914. strcpy(expiryDatestrtemp, "");
  9915. }
  9916. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9917. {
  9918. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9919. }
  9920. else
  9921. {
  9922. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9923. }
  9924. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9925. }
  9926. else
  9927. {
  9928. //wrie original item
  9929. strcpy(expiryDatestrtemp, expiryDatestr);
  9930. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9931. strcpy(statusstrtemp, statusstr);
  9932. }
  9933. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9934. }
  9935. fclose(infile);
  9936. fclose(outfile);
  9937. sprintf(rmFileCmd,"rm -f %s",filename);
  9938. system(rmFileCmd);
  9939. resultRename = rename(tempfile, filename);
  9940. if(resultRename == 0)
  9941. {
  9942. DEBUG_INFO("File renamed successfully");
  9943. }
  9944. else
  9945. {
  9946. DEBUG_INFO("Error: unable to rename the file");
  9947. }
  9948. }
  9949. }
  9950. out:
  9951. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9952. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9953. authorizeRetryTimes = 0;
  9954. }
  9955. char * strtrimc( char * s )
  9956. {
  9957. char * p1 = s;
  9958. char * p2 = s;
  9959. while(*p1 != '\0')
  9960. {
  9961. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9962. {
  9963. if(*p1 != ',')
  9964. {
  9965. p1 ++;
  9966. }
  9967. else
  9968. {
  9969. break;
  9970. }
  9971. }
  9972. if(*p1 != ',')
  9973. {
  9974. * p2 ++ = *p1 ++;
  9975. //printf("p2=%s\n",p2);
  9976. }
  9977. else
  9978. {
  9979. break;
  9980. }
  9981. }
  9982. *p2 = '\0';
  9983. return (s);
  9984. }
  9985. void handleBootNotificationResponse(char *payload, int gun_index)
  9986. {
  9987. mtrace();
  9988. char statusStr[12]={0};
  9989. char currentTimeStr[30]={0};
  9990. int intervalInt = 0;
  9991. struct tm tp;
  9992. char buf[28]={0};
  9993. char timebuf[50]={0};
  9994. DEBUG_INFO("handleBootNotificationResponse...\n");
  9995. json_object *BootNotification;
  9996. BootNotification = json_tokener_parse(payload);
  9997. if(!is_error(BootNotification))
  9998. {
  9999. // Required data
  10000. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10001. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10002. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10003. }
  10004. json_object_put(BootNotification);
  10005. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10006. BootNotificationInterval = intervalInt;
  10007. HeartBeatWaitTime = intervalInt;
  10008. //write back to ShmOCPP16Data->BootNotification
  10009. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10010. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10011. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10012. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10013. {
  10014. server_sign = TRUE;
  10015. server_pending =FALSE;
  10016. }
  10017. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10018. {
  10019. server_pending = TRUE;
  10020. }
  10021. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10022. tp.tm_isdst = -1;
  10023. //time_t utc = mktime(&tp);
  10024. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10025. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10026. sprintf(timebuf,"date -s '%s'",buf);
  10027. system(timebuf);
  10028. srand(time(NULL));
  10029. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10030. //==============================================
  10031. // RTC sync
  10032. //==============================================
  10033. system("/sbin/hwclock -w --systohc");
  10034. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10035. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10036. }
  10037. void handleDataTransferResponse(char *payload, int gun_index)
  10038. {
  10039. char sstr[160]={0};//sstr[200]={ 0 };
  10040. int c = 0;
  10041. char *loc;
  10042. DEBUG_INFO("handleDataTransferResponse ...\n");
  10043. loc = strstr(payload, "status");
  10044. printf("loc=%s\n",loc);
  10045. c = 0;
  10046. while (loc[3+strlen("status")+c] != '\"')
  10047. {
  10048. sstr[c] = loc[3+strlen("status")+c];
  10049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10050. c++;
  10051. }
  10052. sstr[c] = '\0';
  10053. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10054. }
  10055. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10056. {
  10057. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10058. //struct json_object *obj;
  10059. // obj = json_tokener_parse(payload);
  10060. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10061. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10062. //No fields are defined.
  10063. }
  10064. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10065. {
  10066. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10067. //struct json_object *obj;
  10068. // obj = json_tokener_parse(payload);
  10069. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10070. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10071. //No fields are defined.
  10072. }
  10073. void handleHeartbeatResponse(char *payload, int gun_index)
  10074. {
  10075. mtrace();
  10076. struct tm tp;
  10077. char buf[28]={0};
  10078. char timebuf[50]={0};
  10079. DEBUG_INFO("handleHeartbeatResponse...\n");
  10080. json_object *Heartbeat;
  10081. Heartbeat = json_tokener_parse(payload);
  10082. if(!is_error(Heartbeat))
  10083. {
  10084. // Required data
  10085. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10086. }
  10087. json_object_put(BootNotification);
  10088. if(FirstHeartBeat == 0)
  10089. {
  10090. FirstHeartBeat = 1;
  10091. DEBUG_INFO("FirstHeartBeat \n");
  10092. }
  10093. HeartBeatWithNOResponse = 0;
  10094. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10095. tp.tm_isdst = -1;
  10096. //time_t utc = mktime(&tp);
  10097. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10098. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10099. sprintf(timebuf,"date -s '%s'",buf);
  10100. system(timebuf);
  10101. //==============================================
  10102. // RTC sync
  10103. //==============================================
  10104. system("/sbin/hwclock -w --systohc");
  10105. //===============================================
  10106. //Print Out HeartBeat log
  10107. //===============================================
  10108. {
  10109. double diff_t;
  10110. struct tm tp,tp1;
  10111. // BootNotification Receive Time
  10112. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10113. tp.tm_isdst = -1;
  10114. time_t BootNotificationReceiveTime = mktime(&tp);
  10115. //HeartBeat Receive Time
  10116. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10117. tp1.tm_isdst = -1;
  10118. time_t HeartBeatReceiveTime = mktime(&tp1);
  10119. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10120. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10121. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10122. {
  10123. HeartBeatCountPerHour = (int)diff_t / 3600;
  10124. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10125. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10126. }
  10127. }
  10128. }
  10129. void handleMeterValuesResponse(char *payload, int gun_index)
  10130. {
  10131. mtrace();
  10132. DEBUG_INFO("handleMeterValuesResponse...\n");
  10133. }
  10134. void handleStartTransactionResponse(char *payload, int gun_index)
  10135. {
  10136. mtrace();
  10137. //int transactionIdInt = 0;
  10138. FILE *outfile;
  10139. char data[100]={0};
  10140. DEBUG_INFO("handleStartTransactionResponse...\n");
  10141. json_object *StartTransaction;
  10142. StartTransaction = json_tokener_parse(payload);
  10143. if(!is_error(StartTransaction))
  10144. {
  10145. // Required data
  10146. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10147. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10148. // Optional data
  10149. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10150. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10151. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10152. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10153. }
  10154. json_object_put(StartTransaction);
  10155. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10156. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10157. //-----------Start : write to the Queue TransactionId file -----------------//
  10158. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10159. {}
  10160. else
  10161. {
  10162. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10163. if(log == NULL)
  10164. {
  10165. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10166. return ;
  10167. }
  10168. else
  10169. {
  10170. fclose(log);
  10171. }
  10172. }
  10173. // open file for writing
  10174. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10175. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10176. {
  10177. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10178. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10179. fputs(data, outfile);
  10180. fclose (outfile);
  10181. }
  10182. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10183. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10184. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10185. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10186. }
  10187. void handleStatusNotificationResponse(char *payload, int gun_index)
  10188. {
  10189. mtrace();
  10190. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10191. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10192. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10193. }
  10194. void handleStopTransactionnResponse(char *payload, int gun_index)
  10195. {
  10196. mtrace();
  10197. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10198. json_object *StopTransaction;
  10199. StopTransaction = json_tokener_parse(payload);
  10200. if(!is_error(StopTransaction))
  10201. {
  10202. // Optional data
  10203. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10204. {
  10205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10206. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10208. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10210. }
  10211. }
  10212. json_object_put(StopTransaction);
  10213. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10214. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10215. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10216. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10217. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10218. }
  10219. //==========================================
  10220. // Handle Error routine
  10221. //==========================================
  10222. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10223. {
  10224. mtrace();
  10225. #ifdef SystemLogMessage
  10226. DEBUG_INFO("errorCode: %s\n", errorCode);
  10227. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10228. DEBUG_INFO("errorDetails: %s\n", payload);
  10229. #endif
  10230. }
  10231. //===============================================
  10232. // Common routine
  10233. //===============================================
  10234. int initialConfigurationTable(void)
  10235. {
  10236. //clock_t start_t, end_t, total_t;
  10237. FILE *fp;
  10238. FILE *outfile;
  10239. char str[200]={0};
  10240. char sstr[100]={0};
  10241. int c = 0;
  10242. char *loc;
  10243. DEBUG_INFO("initialConfigurationTable...\n");
  10244. //start_t = clock();
  10245. //printf("Starting of the program, start_t = %ld\n", start_t);
  10246. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10247. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10248. {
  10249. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10250. if(outfile == NULL)
  10251. {
  10252. DEBUG_INFO("Error opening file\n");
  10253. return FALSE;
  10254. }
  10255. /*Core Profile*/
  10256. //AllowOfflineTxForUnknownId
  10257. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10258. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10262. //AuthorizationCacheEnabled
  10263. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10267. //AuthorizeRemoteTxRequests
  10268. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10272. //BlinkRepeat
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10277. //ClockAlignedDataInterval
  10278. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10282. //ConnectionTimeOut
  10283. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10287. //GetConfigurationMaxKeys
  10288. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10292. // HeartbeatInterval
  10293. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10297. // LightIntensity
  10298. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10302. // LocalAuthorizeOffline
  10303. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10307. // LocalPreAuthorize
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10312. // MaxEnergyOnInvalidId
  10313. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10316. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10318. // MeterValuesAlignedData
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10323. else
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10326. // MeterValuesAlignedDataMaxLength
  10327. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10331. else
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10334. // MeterValuesSampledData
  10335. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10339. else
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10342. // MeterValuesSampledDataMaxLength
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10347. else
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10350. // MeterValueSampleInterval
  10351. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10355. // MinimumStatusDuration
  10356. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10359. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10361. // NumberOfConnectors
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10365. {
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10367. }
  10368. else
  10369. {
  10370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10371. }
  10372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10373. // ResetRetries
  10374. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10378. // ConnectorPhaseRotation
  10379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10383. // ConnectorPhaseRotationMaxLength
  10384. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10388. // StopTransactionOnEVSideDisconnect
  10389. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10393. // StopTransactionOnInvalidId
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10398. // StopTxnAlignedData
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10403. // StopTxnAlignedDataMaxLength
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10408. // StopTxnSampledData
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10413. else
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10416. // StopTxnSampledDataMaxLength
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10420. {
  10421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10422. }
  10423. else
  10424. {
  10425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10426. }
  10427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10428. // SupportedFeatureProfiles
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10433. // SupportedFeatureProfilesMaxLength
  10434. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10438. // TransactionMessageAttempts
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10442. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10444. // TransactionMessageRetryInterval
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10448. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10450. // UnlockConnectorOnEVSideDisconnect
  10451. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10455. // WebSocketPingInterval
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10460. //* Local Auth List Management Profile*/
  10461. #if 0
  10462. //For OCTT Test Case
  10463. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10466. #endif
  10467. #if 1
  10468. //LocalAuthListEnabled
  10469. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10473. #endif
  10474. //LocalAuthListMaxLength
  10475. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10479. //SendLocalListMaxLength
  10480. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10484. //ReserveConnectorZeroSupported
  10485. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10489. //* Smart Charging Profile */
  10490. //ChargeProfileMaxStackLevel
  10491. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10495. // ChargingScheduleAllowedChargingRateUnit
  10496. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10500. // ChargingScheduleMaxPeriods
  10501. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10505. // ConnectorSwitch3to1PhaseSupported
  10506. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10510. // MaxChargingProfilesInstalled
  10511. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10515. fclose(outfile);
  10516. }
  10517. else
  10518. {
  10519. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10520. char keystr[60]={0};
  10521. char readonlystr[10]={0};
  10522. char valuestr[100]={0};
  10523. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10524. if(fp == NULL) {
  10525. DEBUG_INFO("Error opening file");
  10526. return FALSE;
  10527. }
  10528. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10529. {
  10530. //DEBUG_INFO("Get Configuration \n");
  10531. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10532. //*************************key*********************************/
  10533. loc = strstr(str, "key");
  10534. c = 0;
  10535. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10536. while (loc[strlen("key")+3+c] != '\"')
  10537. {
  10538. sstr[c] = loc[strlen("key")+3+c];
  10539. c++;
  10540. }
  10541. sstr[c] = '\0';
  10542. strcpy(keystr,sstr);
  10543. //*************************readonly*********************************/
  10544. loc = strstr(str, "readonly");
  10545. c = 0;
  10546. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10547. while (loc[strlen("readonly")+2+c] != ',')
  10548. {
  10549. sstr[c] = loc[strlen("readonly")+2+c];
  10550. c++;
  10551. }
  10552. sstr[c] = '\0';
  10553. strcpy(readonlystr,sstr);
  10554. //*************************value*********************************/
  10555. loc = strstr(str, "value");
  10556. c = 0;
  10557. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10558. while (loc[strlen("value")+3+c] != '\"')
  10559. {
  10560. sstr[c] = loc[strlen("value")+3+c];
  10561. c++;
  10562. }
  10563. sstr[c] = '\0';
  10564. strcpy(valuestr,sstr);
  10565. // DEBUG_INFO("keystr=%s\n",keystr);
  10566. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10567. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10568. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10569. {
  10570. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10573. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10574. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10575. }
  10576. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10577. {
  10578. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10579. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10581. }
  10582. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10583. {
  10584. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10586. }
  10587. if(strcmp(keystr, "BlinkRepeat") == 0)
  10588. {
  10589. //Charger.BlinkRepeat = Integer.parseInt(value);
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10592. }
  10593. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10594. {
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10597. }
  10598. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10599. {
  10600. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10602. }
  10603. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10604. {
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10607. }
  10608. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10609. {
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10612. HeartBeatWaitTime = atoi(valuestr);
  10613. }
  10614. if(strcmp(keystr, "LightIntensity") == 0)
  10615. {
  10616. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10618. }
  10619. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10620. {
  10621. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10623. }
  10624. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10625. {
  10626. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10628. }
  10629. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10630. {
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10633. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10634. }
  10635. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10636. {
  10637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10639. }
  10640. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10641. {
  10642. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10644. }
  10645. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10646. {
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10649. }
  10650. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10651. {
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10654. }
  10655. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10656. {
  10657. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10659. }
  10660. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10661. {
  10662. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10664. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10665. }
  10666. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10667. {
  10668. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10670. }
  10671. if(strcmp(keystr, "ResetRetries") == 0)
  10672. {
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10675. }
  10676. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10677. {
  10678. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10680. }
  10681. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10682. {
  10683. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10685. }
  10686. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10687. {
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10690. }
  10691. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10692. {
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10695. }
  10696. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10697. {
  10698. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10700. }
  10701. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10702. {
  10703. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10705. }
  10706. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10707. {
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10710. }
  10711. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10712. {
  10713. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10715. }
  10716. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10717. {
  10718. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10720. }
  10721. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10722. {
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10725. }
  10726. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10727. {
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10730. TransactionMessageAttemptsValue = atoi(valuestr);
  10731. }
  10732. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10733. {
  10734. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10736. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10737. }
  10738. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10739. {
  10740. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10742. }
  10743. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10744. {
  10745. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10747. }
  10748. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10749. {
  10750. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10752. }
  10753. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10754. {
  10755. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10756. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10757. }
  10758. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10759. {
  10760. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10762. }
  10763. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10764. {
  10765. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10767. }
  10768. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10769. {
  10770. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10772. }
  10773. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10774. {
  10775. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10777. }
  10778. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10779. {
  10780. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10782. }
  10783. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10784. {
  10785. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10787. }
  10788. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10789. {
  10790. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10792. }
  10793. }
  10794. fclose(fp);
  10795. }
  10796. return 0;
  10797. }
  10798. void StoreConfigurationTable(void)
  10799. {
  10800. FILE *outfile;
  10801. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10802. if(outfile == NULL)
  10803. {
  10804. DEBUG_INFO("Error opening file");
  10805. return ;
  10806. }
  10807. /*Core Profile*/
  10808. //AllowOfflineTxForUnknownId
  10809. /*
  10810. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10811. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10814. */
  10815. //DEBUG_INFO("data=%s\n",data);
  10816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10817. //AuthorizationCacheEnabled
  10818. /*
  10819. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10822. */
  10823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10824. //AuthorizeRemoteTxRequests
  10825. /*
  10826. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10829. */
  10830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10831. //BlinkRepeat
  10832. /*
  10833. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10836. */
  10837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10838. //ClockAlignedDataInterval
  10839. /*
  10840. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10843. */
  10844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10845. //ConnectionTimeOut
  10846. /*
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10850. */
  10851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10852. //GetConfigurationMaxKeys
  10853. /*
  10854. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10857. */
  10858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10859. // HeartbeatInterval
  10860. /*
  10861. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10864. */
  10865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10866. // LightIntensity
  10867. /*
  10868. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10871. */
  10872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10873. // LocalAuthorizeOffline
  10874. /*
  10875. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10878. */
  10879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10880. // LocalPreAuthorize
  10881. /*
  10882. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10885. */
  10886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10887. // MaxEnergyOnInvalidId
  10888. /*
  10889. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10892. */
  10893. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10895. // MeterValuesAlignedData
  10896. /*
  10897. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10900. */
  10901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10902. // MeterValuesAlignedDataMaxLength
  10903. /*
  10904. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10907. */
  10908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10909. // MeterValuesSampledData
  10910. /*
  10911. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10914. */
  10915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10916. // MeterValuesSampledDataMaxLength
  10917. /*
  10918. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10921. */
  10922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10923. // MeterValueSampleInterval
  10924. /*
  10925. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10928. */
  10929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10930. // MinimumStatusDuration
  10931. /*
  10932. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10935. */
  10936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10937. // NumberOfConnectors
  10938. /*
  10939. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10942. {
  10943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10944. }
  10945. else
  10946. {
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10948. }
  10949. */
  10950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10951. // ResetRetries
  10952. /*
  10953. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10956. */
  10957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10958. // ConnectorPhaseRotation
  10959. /*
  10960. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10963. */
  10964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10965. // ConnectorPhaseRotationMaxLength
  10966. /*
  10967. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10970. */
  10971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10972. // StopTransactionOnEVSideDisconnect
  10973. /*
  10974. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10977. */
  10978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10979. // StopTransactionOnInvalidId
  10980. /*
  10981. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10984. */
  10985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10986. // StopTxnAlignedData
  10987. /*
  10988. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10991. */
  10992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10993. // StopTxnAlignedDataMaxLength
  10994. /*
  10995. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10998. */
  10999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11000. // StopTxnSampledData
  11001. /*
  11002. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11005. */
  11006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11007. // StopTxnSampledDataMaxLength
  11008. /*
  11009. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11012. */
  11013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11014. // SupportedFeatureProfiles
  11015. /*
  11016. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11019. */
  11020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11021. // SupportedFeatureProfilesMaxLength
  11022. /*
  11023. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11026. */
  11027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11028. // TransactionMessageAttempts
  11029. /*
  11030. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11033. */
  11034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11035. // TransactionMessageRetryInterval
  11036. /*
  11037. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11040. */
  11041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11042. // UnlockConnectorOnEVSideDisconnect
  11043. /*
  11044. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11047. */
  11048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11049. // WebSocketPingInterval
  11050. /*
  11051. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11054. */
  11055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11056. //* Local Auth List Management Profile*/
  11057. //LocalAuthListEnabled
  11058. /*
  11059. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11062. */
  11063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11064. //LocalAuthListMaxLength
  11065. /*
  11066. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11069. */
  11070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11071. //SendLocalListMaxLength
  11072. /*
  11073. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11076. */
  11077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11078. //ReserveConnectorZeroSupported
  11079. /*
  11080. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11083. */
  11084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11085. //* Smart Charging Profile */
  11086. //ChargeProfileMaxStackLevel
  11087. /*
  11088. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11091. */
  11092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11093. // ChargingScheduleAllowedChargingRateUnit
  11094. /*
  11095. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11098. */
  11099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11100. // ChargingScheduleMaxPeriods
  11101. /*
  11102. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11105. */
  11106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11107. // ConnectorSwitch3to1PhaseSupported
  11108. /*
  11109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11112. */
  11113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11114. // MaxChargingProfilesInstalled
  11115. /*
  11116. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11119. */
  11120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11121. fclose(outfile);
  11122. }
  11123. void getKeyValue(char *keyReq)
  11124. {
  11125. int isEmpty = FALSE;
  11126. int isKnowKey = FALSE;
  11127. DEBUG_INFO("keyReq = %s\n", keyReq);
  11128. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11129. isEmpty = TRUE;
  11130. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11137. }
  11138. else
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11141. }
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11143. isKnowKey = TRUE;
  11144. }
  11145. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11152. }
  11153. else
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11156. }
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11158. isKnowKey = TRUE;
  11159. }
  11160. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11167. }
  11168. else
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11171. }
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11173. isKnowKey = TRUE;
  11174. }
  11175. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11182. }
  11183. else
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11186. }
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11188. isKnowKey = TRUE;
  11189. }
  11190. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11197. }
  11198. else
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11201. }
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11203. isKnowKey = TRUE;
  11204. }
  11205. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11212. }
  11213. else
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11216. }
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11218. isKnowKey = TRUE;
  11219. }
  11220. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11227. }
  11228. else
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11231. }
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11233. isKnowKey = TRUE;
  11234. }
  11235. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11242. }
  11243. else
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11246. }
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11248. isKnowKey = TRUE;
  11249. }
  11250. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11257. }
  11258. else
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11261. }
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11263. isKnowKey = TRUE;
  11264. }
  11265. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11272. }
  11273. else
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11276. }
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11278. isKnowKey = TRUE;
  11279. }
  11280. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11287. }
  11288. else
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11291. }
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11293. isKnowKey = TRUE;
  11294. }
  11295. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11302. }
  11303. else
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11306. }
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11308. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11309. isKnowKey = TRUE;
  11310. }
  11311. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11318. }
  11319. else
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11322. }
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11324. isKnowKey = TRUE;
  11325. }
  11326. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11333. }
  11334. else
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11337. }
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11339. isKnowKey = TRUE;
  11340. }
  11341. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11348. }
  11349. else
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11352. }
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11354. isKnowKey = TRUE;
  11355. }
  11356. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11363. }
  11364. else
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11367. }
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11369. isKnowKey = TRUE;
  11370. }
  11371. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11378. }
  11379. else
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11382. }
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11384. isKnowKey = TRUE;
  11385. }
  11386. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11393. }
  11394. else
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11397. }
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11399. isKnowKey = TRUE;
  11400. }
  11401. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11408. }
  11409. else
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11412. }
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11414. isKnowKey = TRUE;
  11415. }
  11416. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11423. }
  11424. else
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11427. }
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11429. isKnowKey = TRUE;
  11430. }
  11431. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11438. }
  11439. else
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11442. }
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11444. isKnowKey = TRUE;
  11445. }
  11446. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11453. }
  11454. else
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11457. }
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11459. isKnowKey = TRUE;
  11460. }
  11461. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11468. }
  11469. else
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11472. }
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11474. isKnowKey = TRUE;
  11475. }
  11476. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11483. }
  11484. else
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11487. }
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11489. isKnowKey = TRUE;
  11490. }
  11491. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11498. }
  11499. else
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11502. }
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11504. isKnowKey = TRUE;
  11505. }
  11506. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11513. }
  11514. else
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11517. }
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11519. isKnowKey = TRUE;
  11520. }
  11521. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11528. }
  11529. else
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11532. }
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11534. isKnowKey = TRUE;
  11535. }
  11536. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11543. }
  11544. else
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11547. }
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11549. isKnowKey = TRUE;
  11550. }
  11551. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11558. }
  11559. else
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11562. }
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11564. isKnowKey = TRUE;
  11565. }
  11566. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11573. }
  11574. else
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11577. }
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11579. isKnowKey = TRUE;
  11580. }
  11581. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11586. {
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11588. }
  11589. else
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11592. }
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11594. isKnowKey = TRUE;
  11595. }
  11596. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11601. {
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11603. }
  11604. else
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11607. }
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11609. isKnowKey = TRUE;
  11610. }
  11611. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11616. {
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11618. }
  11619. else
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11622. }
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11624. isKnowKey = TRUE;
  11625. }
  11626. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11631. {
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11633. }
  11634. else
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11637. }
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11639. isKnowKey = TRUE;
  11640. }
  11641. #if 1
  11642. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11646. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11649. }
  11650. else
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11653. }
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11655. isKnowKey = TRUE;
  11656. }
  11657. #endif
  11658. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11662. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11665. }
  11666. else
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11669. }
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11671. isKnowKey = TRUE;
  11672. }
  11673. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11674. {
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11677. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11678. {
  11679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11680. }
  11681. else
  11682. {
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11684. }
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11686. isKnowKey = TRUE;
  11687. }
  11688. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11689. {
  11690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11692. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11693. {
  11694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11695. }
  11696. else
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11699. }
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11701. isKnowKey = TRUE;
  11702. }
  11703. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11704. {
  11705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11707. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11708. {
  11709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11710. }
  11711. else
  11712. {
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11714. }
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11716. isKnowKey = TRUE;
  11717. }
  11718. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11719. {
  11720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11722. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11723. {
  11724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11725. }
  11726. else
  11727. {
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11729. }
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11731. isKnowKey = TRUE;
  11732. }
  11733. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11734. {
  11735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11737. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11738. {
  11739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11740. }
  11741. else
  11742. {
  11743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11744. }
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11746. isKnowKey = TRUE;
  11747. }
  11748. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11749. {
  11750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11752. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11753. {
  11754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11755. }
  11756. else
  11757. {
  11758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11759. }
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11761. isKnowKey = TRUE;
  11762. }
  11763. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11764. {
  11765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11767. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11768. {
  11769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11770. }
  11771. else
  11772. {
  11773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11774. }
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11776. isKnowKey = TRUE;
  11777. }
  11778. //=========================================================
  11779. if(!isEmpty && !isKnowKey)
  11780. {
  11781. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11782. strcpy(unknownkey[UnknownKeynum], keyReq);
  11783. UnknownKeynum = UnknownKeynum + 1;
  11784. }
  11785. }
  11786. void processUnkownKey(void)
  11787. {
  11788. DEBUG_INFO("processUnkownKey...\n");
  11789. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11790. for(int index=0; index < UnknownKeynum; index++)
  11791. {
  11792. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11793. {
  11794. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11795. }
  11796. }
  11797. }
  11798. int setKeyValue(char *key, char *value)
  11799. {
  11800. int isSuccess = NotSupported;
  11801. int check_ascii=0;
  11802. char str[10]={0};
  11803. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11804. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11805. {
  11806. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11808. {
  11809. strcpy(str, (const char*)value);
  11810. for(int i = 0; str[i]; i++){
  11811. str[i] = tolower(str[i]);
  11812. }
  11813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11814. isSuccess = ConfigurationStatus_Accepted;
  11815. }
  11816. else
  11817. {
  11818. isSuccess = ConfigurationStatus_Rejected;
  11819. }
  11820. }
  11821. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11822. {
  11823. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11825. {
  11826. strcpy(str, (const char*)value);
  11827. for(int i = 0; str[i]; i++){
  11828. str[i] = tolower(str[i]);
  11829. }
  11830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11831. isSuccess = ConfigurationStatus_Accepted;
  11832. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11833. }
  11834. else
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. }
  11839. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11840. {
  11841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11842. {
  11843. strcpy(str, (const char*)value);
  11844. for(int i = 0; str[i]; i++)
  11845. {
  11846. str[i] = tolower(str[i]);
  11847. }
  11848. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11850. isSuccess = ConfigurationStatus_Accepted;
  11851. }
  11852. else
  11853. {
  11854. isSuccess = ConfigurationStatus_Rejected;
  11855. }
  11856. }
  11857. if(strcmp(key, "BlinkRepeat") == 0)
  11858. {
  11859. //Charger.BlinkRepeat = Integer.parseInt(value);
  11860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11861. {
  11862. check_ascii = value[0];
  11863. if( (check_ascii < 48) || (check_ascii > 57) )
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. else
  11868. {
  11869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11870. isSuccess = ConfigurationStatus_Accepted;
  11871. }
  11872. }
  11873. else
  11874. {
  11875. isSuccess = ConfigurationStatus_Rejected;
  11876. }
  11877. }
  11878. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11879. {
  11880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11881. {
  11882. check_ascii = value[0];
  11883. if( (check_ascii < 48) || (check_ascii > 57) )
  11884. {
  11885. isSuccess = ConfigurationStatus_Rejected;
  11886. }
  11887. else
  11888. {
  11889. if((atoi(value) == 0) || (atoi(value) >= 10))
  11890. {
  11891. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11893. isSuccess = ConfigurationStatus_Accepted;
  11894. }
  11895. else
  11896. isSuccess = ConfigurationStatus_Rejected;
  11897. }
  11898. }
  11899. else
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. }
  11904. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11905. {
  11906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11907. {
  11908. check_ascii = value[0];
  11909. if( (check_ascii < 48) || (check_ascii > 57) )
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. else
  11914. {
  11915. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11928. {
  11929. check_ascii = value[0];
  11930. if( (check_ascii < 48) || (check_ascii > 57) )
  11931. {
  11932. isSuccess = ConfigurationStatus_Rejected;
  11933. }
  11934. else
  11935. {
  11936. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11938. isSuccess = ConfigurationStatus_Accepted;
  11939. }
  11940. }
  11941. else
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. }
  11946. if(strcmp(key, "HeartbeatInterval") == 0)
  11947. {
  11948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11949. {
  11950. check_ascii = value[0];
  11951. if( (check_ascii < 48) || (check_ascii > 57) )
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. else
  11956. {
  11957. if((atoi(value) == 0) || (atoi(value) >= 10))
  11958. {
  11959. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11961. HeartBeatWaitTime = atoi(value);
  11962. isSuccess = ConfigurationStatus_Accepted;
  11963. }
  11964. else
  11965. {
  11966. isSuccess = ConfigurationStatus_Rejected;
  11967. }
  11968. }
  11969. }
  11970. else
  11971. {
  11972. isSuccess = ConfigurationStatus_Rejected;
  11973. }
  11974. }
  11975. if(strcmp(key, "LightIntensity") == 0)
  11976. {
  11977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11978. {
  11979. check_ascii = value[0];
  11980. if( (check_ascii < 48) || (check_ascii > 57) )
  11981. {
  11982. isSuccess = ConfigurationStatus_Rejected;
  11983. }
  11984. else
  11985. {
  11986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11987. isSuccess = ConfigurationStatus_Accepted;
  11988. }
  11989. }
  11990. else
  11991. {
  11992. isSuccess = ConfigurationStatus_Rejected;
  11993. }
  11994. }
  11995. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11996. {
  11997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11998. {
  11999. strcpy(str, (const char*)value);
  12000. for(int i = 0; str[i]; i++)
  12001. {
  12002. str[i] = tolower(str[i]);
  12003. }
  12004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12005. isSuccess = ConfigurationStatus_Accepted;
  12006. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12007. }
  12008. else
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. }
  12013. if(strcmp(key, "LocalPreAuthorize") == 0)
  12014. {
  12015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12016. {
  12017. strcpy(str, (const char*)value);
  12018. for(int i = 0; str[i]; i++)
  12019. {
  12020. str[i] = tolower(str[i]);
  12021. }
  12022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12023. isSuccess = ConfigurationStatus_Accepted;
  12024. }
  12025. else
  12026. {
  12027. isSuccess = ConfigurationStatus_Rejected;
  12028. }
  12029. }
  12030. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12031. {
  12032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12033. {
  12034. check_ascii = value[0];
  12035. if( (check_ascii < 48) || (check_ascii > 57) )
  12036. {
  12037. isSuccess = ConfigurationStatus_Rejected;
  12038. }
  12039. else
  12040. {
  12041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12042. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12043. isSuccess = ConfigurationStatus_Accepted;
  12044. }
  12045. }
  12046. else
  12047. {
  12048. isSuccess = ConfigurationStatus_Rejected;
  12049. }
  12050. }
  12051. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12052. {
  12053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12054. {
  12055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12056. isSuccess = ConfigurationStatus_Accepted;
  12057. }
  12058. else
  12059. {
  12060. isSuccess = ConfigurationStatus_Rejected;
  12061. }
  12062. }
  12063. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12064. {
  12065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12066. {
  12067. check_ascii = value[0];
  12068. if( (check_ascii < 48) || (check_ascii > 57) )
  12069. {
  12070. isSuccess = ConfigurationStatus_Rejected;
  12071. }
  12072. else
  12073. {
  12074. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12076. isSuccess = ConfigurationStatus_Accepted;
  12077. }
  12078. }
  12079. else
  12080. {
  12081. isSuccess = ConfigurationStatus_Rejected;
  12082. }
  12083. }
  12084. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12085. {
  12086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12087. {
  12088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12089. isSuccess = ConfigurationStatus_Accepted;
  12090. }
  12091. else
  12092. {
  12093. isSuccess = ConfigurationStatus_Rejected;
  12094. }
  12095. }
  12096. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12097. {
  12098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12099. {
  12100. check_ascii = value[0];
  12101. if( (check_ascii < 48) || (check_ascii > 57) )
  12102. {
  12103. isSuccess = ConfigurationStatus_Rejected;
  12104. }
  12105. else
  12106. {
  12107. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12109. isSuccess = ConfigurationStatus_Accepted;
  12110. }
  12111. }
  12112. else
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. }
  12117. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12118. {
  12119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12120. {
  12121. check_ascii = value[0];
  12122. if( (check_ascii < 48) || (check_ascii > 57) )
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. else
  12127. {
  12128. if((atoi(value) == 0) || (atoi(value) >= 10))
  12129. {
  12130. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12132. isSuccess = ConfigurationStatus_Accepted;
  12133. }
  12134. else
  12135. {
  12136. isSuccess = ConfigurationStatus_Rejected;
  12137. }
  12138. }
  12139. }
  12140. else
  12141. {
  12142. isSuccess = ConfigurationStatus_Rejected;
  12143. }
  12144. }
  12145. if(strcmp(key, "MinimumStatusDuration") == 0)
  12146. {
  12147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12148. {
  12149. check_ascii = value[0];
  12150. if( (check_ascii < 48) || (check_ascii > 57) )
  12151. {
  12152. isSuccess = ConfigurationStatus_Rejected;
  12153. }
  12154. else
  12155. {
  12156. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12157. {
  12158. isSuccess = ConfigurationStatus_Rejected;
  12159. }
  12160. else
  12161. {
  12162. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12164. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12165. isSuccess = ConfigurationStatus_Accepted;
  12166. }
  12167. }
  12168. }
  12169. else
  12170. {
  12171. isSuccess = ConfigurationStatus_Rejected;
  12172. }
  12173. }
  12174. if(strcmp(key, "NumberOfConnectors") == 0)
  12175. {
  12176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12177. {
  12178. check_ascii = value[0];
  12179. if( (check_ascii < 48) || (check_ascii > 57) )
  12180. {
  12181. isSuccess = ConfigurationStatus_Rejected;
  12182. }
  12183. else
  12184. {
  12185. //Charger.ResetRetries = Integer.parseInt(value);
  12186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12187. isSuccess = ConfigurationStatus_Accepted;
  12188. }
  12189. }
  12190. else
  12191. {
  12192. isSuccess = ConfigurationStatus_Rejected;
  12193. }
  12194. }
  12195. if(strcmp(key, "ResetRetries") == 0)
  12196. {
  12197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12198. {
  12199. check_ascii = value[0];
  12200. if( (check_ascii < 48) || (check_ascii > 57) )
  12201. {
  12202. isSuccess = ConfigurationStatus_Rejected;
  12203. }
  12204. else
  12205. {
  12206. //Charger.ResetRetries = Integer.parseInt(value);
  12207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12208. isSuccess = ConfigurationStatus_Accepted;
  12209. }
  12210. }
  12211. else
  12212. {
  12213. isSuccess = ConfigurationStatus_Rejected;
  12214. }
  12215. }
  12216. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12217. {
  12218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12219. {
  12220. strcpy(str, (const char*)value);
  12221. for(int i = 0; str[i]; i++)
  12222. {
  12223. str[i] = tolower(str[i]);
  12224. }
  12225. if(strcmp(str, "notapplicable")== 0)
  12226. {
  12227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12228. isSuccess = ConfigurationStatus_Accepted;
  12229. }
  12230. else if(strcmp(str, "unknown")== 0)
  12231. {
  12232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12233. isSuccess = ConfigurationStatus_Accepted;
  12234. }
  12235. else if(strcmp(str, "rst")== 0)
  12236. {
  12237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12238. isSuccess = ConfigurationStatus_Accepted;
  12239. }
  12240. else if(strcmp(str, "rts")== 0)
  12241. {
  12242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12243. isSuccess = ConfigurationStatus_Accepted;
  12244. }
  12245. else if(strcmp(str, "srt")== 0)
  12246. {
  12247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12248. isSuccess = ConfigurationStatus_Accepted;
  12249. }
  12250. else if(strcmp(str, "str")== 0)
  12251. {
  12252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12253. isSuccess = ConfigurationStatus_Accepted;
  12254. }
  12255. else if(strcmp(str, "trs")== 0)
  12256. {
  12257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12258. isSuccess = ConfigurationStatus_Accepted;
  12259. }
  12260. else if(strcmp(str, "tsr")== 0)
  12261. {
  12262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12263. isSuccess = ConfigurationStatus_Accepted;
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. else
  12271. {
  12272. isSuccess = ConfigurationStatus_Rejected;
  12273. }
  12274. }
  12275. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12276. {
  12277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12278. {
  12279. check_ascii = value[0];
  12280. if( (check_ascii < 48) || (check_ascii > 57) )
  12281. {
  12282. isSuccess = ConfigurationStatus_Rejected;
  12283. }
  12284. else
  12285. {
  12286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12287. isSuccess = ConfigurationStatus_Accepted;
  12288. }
  12289. }
  12290. else
  12291. {
  12292. isSuccess = ConfigurationStatus_Rejected;
  12293. }
  12294. }
  12295. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12296. {
  12297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12298. {
  12299. strcpy(str, (const char*)value);
  12300. for(int i = 0; str[i]; i++)
  12301. {
  12302. str[i] = tolower(str[i]);
  12303. }
  12304. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12306. isSuccess = ConfigurationStatus_Accepted;
  12307. }
  12308. else
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. }
  12313. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12316. {
  12317. strcpy(str, (const char*)value);
  12318. for(int i = 0; str[i]; i++)
  12319. {
  12320. str[i] = tolower(str[i]);
  12321. }
  12322. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12324. isSuccess = ConfigurationStatus_Accepted;
  12325. }
  12326. else
  12327. {
  12328. isSuccess = ConfigurationStatus_Rejected;
  12329. }
  12330. }
  12331. if(strcmp(key, "StopTxnAlignedData") == 0)
  12332. {
  12333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12334. {
  12335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12336. isSuccess = ConfigurationStatus_Accepted;
  12337. }
  12338. else
  12339. {
  12340. isSuccess = ConfigurationStatus_Rejected;
  12341. }
  12342. }
  12343. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12344. {
  12345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12346. {
  12347. check_ascii = value[0];
  12348. if( (check_ascii < 48) || (check_ascii > 57) )
  12349. {
  12350. isSuccess = ConfigurationStatus_Rejected;
  12351. }
  12352. else
  12353. {
  12354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12355. isSuccess = ConfigurationStatus_Accepted;
  12356. }
  12357. }
  12358. else
  12359. {
  12360. isSuccess = ConfigurationStatus_Rejected;
  12361. }
  12362. }
  12363. if(strcmp(key, "StopTxnSampledData") == 0)
  12364. {
  12365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12366. {
  12367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12368. isSuccess = ConfigurationStatus_Accepted;
  12369. }
  12370. else
  12371. {
  12372. isSuccess = ConfigurationStatus_Rejected;
  12373. }
  12374. }
  12375. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12376. {
  12377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12378. {
  12379. check_ascii = value[0];
  12380. if( (check_ascii < 48) || (check_ascii > 57) )
  12381. {
  12382. isSuccess = ConfigurationStatus_Rejected;
  12383. }
  12384. else
  12385. {
  12386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12387. isSuccess = ConfigurationStatus_Accepted;
  12388. }
  12389. }
  12390. else
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. }
  12395. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12396. {
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12398. {
  12399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12400. isSuccess = ConfigurationStatus_Accepted;
  12401. }
  12402. else
  12403. {
  12404. isSuccess = ConfigurationStatus_Rejected;
  12405. }
  12406. }
  12407. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12408. {
  12409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12410. {
  12411. check_ascii = value[0];
  12412. if( (check_ascii < 48) || (check_ascii > 57) )
  12413. {
  12414. isSuccess = ConfigurationStatus_Rejected;
  12415. }
  12416. else
  12417. {
  12418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12419. isSuccess = ConfigurationStatus_Accepted;
  12420. }
  12421. }
  12422. else
  12423. {
  12424. isSuccess = ConfigurationStatus_Rejected;
  12425. }
  12426. }
  12427. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12428. {
  12429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12430. {
  12431. check_ascii = value[0];
  12432. if( (check_ascii < 48) || (check_ascii > 57) )
  12433. {
  12434. isSuccess = ConfigurationStatus_Rejected;
  12435. }
  12436. else
  12437. {
  12438. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12440. TransactionMessageAttemptsValue = atoi(value);
  12441. isSuccess = ConfigurationStatus_Accepted;
  12442. }
  12443. }
  12444. else
  12445. {
  12446. isSuccess = ConfigurationStatus_Rejected;
  12447. }
  12448. }
  12449. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12450. {
  12451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12452. {
  12453. check_ascii = value[0];
  12454. if( (check_ascii < 48) || (check_ascii > 57) )
  12455. {
  12456. isSuccess = ConfigurationStatus_Rejected;
  12457. }
  12458. else
  12459. {
  12460. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12462. TransactionMessageRetryIntervalValue = atoi(value);
  12463. isSuccess = ConfigurationStatus_Accepted;
  12464. }
  12465. }
  12466. else
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. }
  12471. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12472. {
  12473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12474. {
  12475. strcpy(str, (const char*)value);
  12476. for(int i = 0; str[i]; i++)
  12477. {
  12478. str[i] = tolower(str[i]);
  12479. }
  12480. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12482. isSuccess = ConfigurationStatus_Accepted;
  12483. }
  12484. else
  12485. {
  12486. isSuccess = ConfigurationStatus_Rejected;
  12487. }
  12488. }
  12489. if(strcmp(key, "WebSocketPingInterval") == 0)
  12490. {
  12491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12492. {
  12493. check_ascii = value[0];
  12494. if( (check_ascii < 48) || (check_ascii > 57) )
  12495. {
  12496. isSuccess = ConfigurationStatus_Rejected;
  12497. }
  12498. else
  12499. {
  12500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12501. isSuccess = ConfigurationStatus_Accepted;
  12502. }
  12503. }
  12504. else
  12505. {
  12506. isSuccess = ConfigurationStatus_Rejected;
  12507. }
  12508. }
  12509. #if 0
  12510. //For OCPP Test Case
  12511. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12512. {
  12513. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12514. {
  12515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12516. isSuccess = ConfigurationStatus_Accepted;
  12517. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12518. }
  12519. else
  12520. {
  12521. isSuccess = ConfigurationStatus_Rejected;
  12522. }
  12523. }
  12524. #endif
  12525. #if 1
  12526. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12527. {
  12528. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12529. {
  12530. strcpy(str, (const char*)value);
  12531. for(int i = 0; str[i]; i++)
  12532. {
  12533. str[i] = tolower(str[i]);
  12534. }
  12535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12536. isSuccess = ConfigurationStatus_Accepted;
  12537. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12538. }
  12539. else
  12540. {
  12541. isSuccess = ConfigurationStatus_Rejected;
  12542. }
  12543. }
  12544. #endif
  12545. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12546. {
  12547. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12548. {
  12549. check_ascii = value[0];
  12550. if( (check_ascii < 48) || (check_ascii > 57) )
  12551. {
  12552. isSuccess = ConfigurationStatus_Rejected;
  12553. }
  12554. else
  12555. {
  12556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12557. isSuccess = ConfigurationStatus_Accepted;
  12558. }
  12559. }
  12560. else
  12561. {
  12562. isSuccess = ConfigurationStatus_Rejected;
  12563. }
  12564. }
  12565. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12566. {
  12567. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12568. {
  12569. check_ascii = value[0];
  12570. if( (check_ascii < 48) || (check_ascii > 57) )
  12571. {
  12572. isSuccess = ConfigurationStatus_Rejected;
  12573. }
  12574. else
  12575. {
  12576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12577. isSuccess = ConfigurationStatus_Accepted;
  12578. }
  12579. }
  12580. else
  12581. {
  12582. isSuccess = ConfigurationStatus_Rejected;
  12583. }
  12584. }
  12585. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12586. {
  12587. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12588. {
  12589. strcpy(str, (const char*)value);
  12590. for(int i = 0; str[i]; i++)
  12591. {
  12592. str[i] = tolower(str[i]);
  12593. }
  12594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12595. isSuccess = ConfigurationStatus_Accepted;
  12596. }
  12597. else
  12598. {
  12599. isSuccess = ConfigurationStatus_Rejected;
  12600. }
  12601. }
  12602. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12603. {
  12604. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12605. {
  12606. check_ascii = value[0];
  12607. if( (check_ascii < 48) || (check_ascii > 57) )
  12608. {
  12609. isSuccess = ConfigurationStatus_Rejected;
  12610. }
  12611. else
  12612. {
  12613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12614. isSuccess = ConfigurationStatus_Accepted;
  12615. }
  12616. }
  12617. else
  12618. {
  12619. isSuccess = ConfigurationStatus_Rejected;
  12620. }
  12621. }
  12622. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12623. {
  12624. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12625. {
  12626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12627. isSuccess = ConfigurationStatus_Accepted;
  12628. }
  12629. else
  12630. {
  12631. isSuccess = ConfigurationStatus_Rejected;
  12632. }
  12633. }
  12634. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12635. {
  12636. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12637. {
  12638. check_ascii = value[0];
  12639. if( (check_ascii < 48) || (check_ascii > 57) )
  12640. {
  12641. isSuccess = ConfigurationStatus_Rejected;
  12642. }
  12643. else
  12644. {
  12645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12646. isSuccess = ConfigurationStatus_Accepted;
  12647. }
  12648. }
  12649. else
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. }
  12654. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12655. {
  12656. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12657. {
  12658. strcpy(str, (const char*)value);
  12659. for(int i = 0; str[i]; i++)
  12660. {
  12661. str[i] = tolower(str[i]);
  12662. }
  12663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12664. isSuccess = ConfigurationStatus_Accepted;
  12665. }
  12666. else
  12667. {
  12668. isSuccess = ConfigurationStatus_Rejected;
  12669. }
  12670. }
  12671. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12672. {
  12673. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12674. {
  12675. check_ascii = value[0];
  12676. if( (check_ascii < 48) || (check_ascii > 57) )
  12677. {
  12678. isSuccess = ConfigurationStatus_Rejected;
  12679. }
  12680. else
  12681. {
  12682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12683. isSuccess = ConfigurationStatus_Accepted;
  12684. }
  12685. }
  12686. else
  12687. {
  12688. isSuccess = ConfigurationStatus_Rejected;
  12689. }
  12690. }
  12691. return isSuccess;
  12692. }
  12693. int TransactionMessageAttemptsGet(void)
  12694. {
  12695. return TransactionMessageAttemptsValue;
  12696. }
  12697. int FirstHeartBeatResponse(void)
  12698. {
  12699. return FirstHeartBeat;
  12700. }
  12701. int TransactionMessageRetryIntervalGet(void)
  12702. {
  12703. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12704. }
  12705. int ReadHttpStatus(int sock)
  12706. {
  12707. //char c;
  12708. char buff[1024]="",*ptr=buff+1;
  12709. int bytes_received, status;
  12710. DEBUG_INFO("Begin Response ..\n");
  12711. while((bytes_received = recv(sock, ptr, 1, 0))){
  12712. if(bytes_received==-1){
  12713. perror("ReadHttpStatus");
  12714. exit(1);
  12715. }
  12716. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12717. ptr++;
  12718. }
  12719. *ptr=0;
  12720. ptr=buff+1;
  12721. sscanf(ptr,"%*s %d ", &status);
  12722. DEBUG_INFO("%s\n",ptr);
  12723. DEBUG_INFO("status=%d\n",status);
  12724. DEBUG_INFO("End Response ..\n");
  12725. return (bytes_received>0)?status:0;
  12726. }
  12727. //the only filed that it parsed is 'Content-Length'
  12728. int ParseHeader(int sock)
  12729. {
  12730. //char c;
  12731. char buff[1024]="",*ptr=buff+4;
  12732. int bytes_received;
  12733. DEBUG_INFO("Begin HEADER ..\n");
  12734. while((bytes_received = recv(sock, ptr, 1, 0))){
  12735. if(bytes_received==-1){
  12736. perror("Parse Header");
  12737. exit(1);
  12738. }
  12739. if(
  12740. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12741. (ptr[-1]=='\r') && (*ptr=='\n' )
  12742. ) break;
  12743. ptr++;
  12744. }
  12745. *ptr=0;
  12746. ptr=buff+4;
  12747. //printf("%s",ptr);
  12748. if(bytes_received){
  12749. ptr=strstr(ptr,"Content-Length:");
  12750. if(ptr){
  12751. sscanf(ptr,"%*s %d",&bytes_received);
  12752. }else
  12753. bytes_received=-1; //unknown size
  12754. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12755. }
  12756. DEBUG_INFO("End HEADER ..\n");
  12757. return bytes_received ;
  12758. }
  12759. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12760. {
  12761. char rmFileCmd[100]={0};
  12762. char FilePath[100]={0};
  12763. char ftpbuf[200];
  12764. int systemresult;
  12765. //DEBUG_INFO("filename=%s\n",filename);
  12766. //DEBUG_INFO("url=%s\n",url);
  12767. sprintf(FilePath,"/mnt/%s",filename);
  12768. if((access(FilePath,F_OK))!=-1)
  12769. {
  12770. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12771. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12772. system(rmFileCmd);
  12773. }
  12774. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12775. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12776. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12777. systemresult = system(ftpbuf);
  12778. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12779. if(systemresult != 0)
  12780. {
  12781. DEBUG_INFO("http DownLoad error!\n");
  12782. return FALSE;
  12783. }
  12784. return TRUE;
  12785. }
  12786. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12787. {
  12788. char rmFileCmd[100]={0};
  12789. char FilePath[100]={0};
  12790. char ftpbuf[200];
  12791. int systemresult;
  12792. //char temp[100];
  12793. sprintf(FilePath,"/mnt/%s",filename);
  12794. if((access(FilePath,F_OK))!=-1)
  12795. {
  12796. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12797. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12798. system(rmFileCmd);
  12799. }
  12800. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12801. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12802. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12803. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12804. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12805. systemresult = system(ftpbuf);
  12806. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12807. if(systemresult != 0)
  12808. {
  12809. printf("wget error!\n");
  12810. return FALSE;
  12811. }
  12812. return TRUE;
  12813. }
  12814. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12815. {
  12816. char rmFileCmd[100]={0};
  12817. char FilePath[100]={0};
  12818. char ftpbuf[200];
  12819. int systemresult;
  12820. //DEBUG_INFO("filename=%s\n",filename);
  12821. //DEBUG_INFO("url=%s\n",url);
  12822. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12823. if((access(FilePath,F_OK))!=-1)
  12824. {
  12825. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12826. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12827. system(rmFileCmd);
  12828. }
  12829. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12830. if(fp == NULL)
  12831. {
  12832. DEBUG_INFO("log is NULL\n");
  12833. return FALSE;
  12834. }
  12835. else
  12836. {
  12837. fprintf(fp, "%s\n", url);
  12838. fprintf(fp, "%s\n", filename);
  12839. fclose(fp);
  12840. }
  12841. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12842. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12843. systemresult = system(ftpbuf);
  12844. DEBUG_INFO("systemresult = %d\n",systemresult);
  12845. if(systemresult != 0)
  12846. {
  12847. DEBUG_INFO("http upload error!\n");
  12848. return FALSE;
  12849. }
  12850. return TRUE;
  12851. }
  12852. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12853. {
  12854. struct hostent* server;
  12855. char *IPbuffer;
  12856. char ftpbuf[200];
  12857. int systemresult;
  12858. // To retrieve host information
  12859. server = gethostbyname(location);
  12860. // To convert an Internet network
  12861. // address into ASCII string
  12862. IPbuffer = inet_ntoa(*((struct in_addr*)
  12863. server->h_addr_list[0]));
  12864. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12865. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12866. /* format : ftpput -u username -p passwd IP target source*/
  12867. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12868. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12869. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12870. systemresult = system(ftpbuf);
  12871. DEBUG_INFO("systemresult=%d\n",systemresult);
  12872. if(systemresult != 0)
  12873. {
  12874. DEBUG_INFO("ftpput error!\n");
  12875. return FALSE;
  12876. }
  12877. return TRUE;
  12878. }
  12879. /**
  12880. * Place the contents of the specified file into a memory buffer
  12881. *
  12882. * @param[in] filename The path and name of the file to read
  12883. * @param[out] filebuffer A pointer to the contents in memory
  12884. * @return status 0 success, 1 on failure
  12885. */
  12886. int get_file_contents(const char* filename, char** outbuffer) {
  12887. FILE* file = NULL;
  12888. long filesize;
  12889. const int blocksize = 1;
  12890. size_t readsize;
  12891. char* filebuffer;
  12892. // Open the file
  12893. file = fopen(filename, "r");
  12894. if (NULL == file)
  12895. {
  12896. printf("'%s' not opened\n", filename);
  12897. exit(EXIT_FAILURE);
  12898. }
  12899. // Determine the file size
  12900. fseek(file, 0, SEEK_END);
  12901. filesize = ftell(file);
  12902. rewind (file);
  12903. // Allocate memory for the file contents
  12904. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12905. *outbuffer = filebuffer;
  12906. if (filebuffer == NULL)
  12907. {
  12908. fputs ("malloc out-of-memory", stderr);
  12909. exit(EXIT_FAILURE);
  12910. }
  12911. // Read in the file
  12912. readsize = fread(filebuffer, blocksize, filesize, file);
  12913. if (readsize != filesize)
  12914. {
  12915. fputs ("didn't read file completely",stderr);
  12916. exit(EXIT_FAILURE);
  12917. }
  12918. // Clean exit
  12919. fclose(file);
  12920. return EXIT_SUCCESS;
  12921. }
  12922. static int selectSqlCount = 0;
  12923. static int callback(void *data, int argc, char **argv, char **azColName){
  12924. int i;
  12925. //printf("%s: ", (const char*)data);
  12926. selectSqlCount = argc;
  12927. for(i = 0; i<argc; i++){
  12928. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12929. }
  12930. //printf("\n");
  12931. return 0;
  12932. }
  12933. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12934. //int i;
  12935. //printf("%s:\n", (const char*)data);
  12936. localversion = argv[5] ? atoi(argv[5]) : 0;
  12937. //printf("localversion=%d\n", localversion);
  12938. return 0;
  12939. }
  12940. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12941. //int i;
  12942. //printf("%s:\n", (const char*)data);
  12943. //idTag
  12944. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12945. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12946. //parentIdTag
  12947. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12948. //expir_date
  12949. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12950. //status
  12951. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12952. //version
  12953. idTagQuery.listVersionInt = atoi(argv[5]);
  12954. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12955. return 0;
  12956. }
  12957. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12958. {
  12959. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12960. // printf("localversion=%d\n", localversion);
  12961. return 0;
  12962. }
  12963. //=========================================
  12964. // Sqlite3 related function
  12965. //=========================================
  12966. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12967. {
  12968. for (int i = 0; i < n_columns; i++)
  12969. {
  12970. DEBUG_INFO("%s/t", col_values[i]);
  12971. }
  12972. DEBUG_INFO("/n");
  12973. return 0;
  12974. }
  12975. void OCPP_getListVerion()
  12976. {
  12977. int rc = 0;
  12978. // const char* data = "Callback function called";
  12979. char sql[100];
  12980. char zErrMsg[100];
  12981. memset(sql, 0, 100);
  12982. memset(zErrMsg, 0, 100);
  12983. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12984. /* Execute SQL statement */
  12985. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12986. if( rc != SQLITE_OK )
  12987. {
  12988. DEBUG_INFO("SQL error: %s", zErrMsg);
  12989. }
  12990. }
  12991. void OCPP_getIdTag(char idTag[])
  12992. {
  12993. int rc = 0;
  12994. // const char* data = "Callback function called";
  12995. char sql[100];
  12996. char zErrMsg[100];
  12997. memset(sql, 0, 100);
  12998. memset(zErrMsg, 0, 100);
  12999. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13000. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13001. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13002. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13003. /* Execute SQL statement */
  13004. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13005. if( rc != SQLITE_OK )
  13006. {
  13007. DEBUG_INFO("SQL error: %s", zErrMsg);
  13008. }
  13009. //return ver;
  13010. }
  13011. void OCPP_get_TableAuthlocalAllData(void)
  13012. {
  13013. int rc = 0;
  13014. char sql[100];
  13015. char zErrMsg[100];
  13016. memset(sql, 0, 100);
  13017. memset(zErrMsg, 0, 100);
  13018. sprintf(sql,"select * from ocpp_auth_local ");
  13019. /* Execute SQL statement */
  13020. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13021. if( rc != SQLITE_OK )
  13022. {
  13023. DEBUG_INFO("SQL error: %s", zErrMsg);
  13024. }
  13025. //return ver;
  13026. }
  13027. int OCPP_cleanLocalList()
  13028. {
  13029. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13030. char *errMsg = 0;
  13031. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13032. if (SQLITE_OK != rc)
  13033. {
  13034. DEBUG_INFO("%s\n",errMsg);
  13035. return FALSE;
  13036. }
  13037. return TRUE;
  13038. }
  13039. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13040. {
  13041. int isSuccess = FALSE;
  13042. int ret = 0;
  13043. //const char* data = "Callback function called";
  13044. char sql[300];
  13045. char zErrMsg[200];
  13046. memset(sql, 0, 300);
  13047. memset(zErrMsg, 0, 200);
  13048. 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);
  13049. //* Execute SQL statement */
  13050. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13051. if( ret != SQLITE_OK )
  13052. {
  13053. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13054. return isSuccess;
  13055. }
  13056. memset(sql, 0, 300);
  13057. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13058. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13059. if( ret != SQLITE_OK )
  13060. {
  13061. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13062. return isSuccess;
  13063. }
  13064. isSuccess = TRUE;
  13065. return isSuccess;
  13066. }
  13067. void OCPP_deleteIdTag(char idTag[])
  13068. {
  13069. //int ver = 0;
  13070. //int isSuccess = FALSE;
  13071. int rc = 0;
  13072. char sql[100];
  13073. char zErrMsg[100];
  13074. memset(sql, 0, 100);
  13075. memset(zErrMsg, 0, 100);
  13076. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13077. //* Execute SQL statement */
  13078. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13079. if( rc != SQLITE_OK )
  13080. {
  13081. DEBUG_INFO("SQL error: %s", zErrMsg);
  13082. }
  13083. }
  13084. int GetOcppServerURL()
  13085. {
  13086. int result = FALSE;
  13087. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13088. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13089. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13090. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13091. {
  13092. #if 1
  13093. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13094. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13095. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13096. #endif
  13097. result = TRUE;
  13098. goto End;
  13099. }
  13100. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13101. {
  13102. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13103. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13104. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13105. result = TRUE;
  13106. goto End;
  13107. }
  13108. else
  13109. {
  13110. strcpy(OcppHost,"");
  13111. }
  13112. End:
  13113. return result;
  13114. }
  13115. int GetOcppPath()
  13116. {
  13117. int result = FALSE;
  13118. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13119. {
  13120. if(OcppTempPath == NULL)
  13121. {
  13122. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13123. }
  13124. else
  13125. {
  13126. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13127. }
  13128. result = TRUE;
  13129. goto End;
  13130. }
  13131. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13132. {
  13133. if(OcppTempPath == NULL)
  13134. {
  13135. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13136. }
  13137. else
  13138. {
  13139. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13140. }
  13141. result = TRUE;
  13142. goto End;
  13143. }
  13144. else
  13145. {
  13146. strcpy(OcppPath,"");
  13147. }
  13148. End:
  13149. return result;
  13150. }
  13151. int GetOcppPort()
  13152. {
  13153. return OcppPort;
  13154. }
  13155. int GetOcppConnStatus(void)
  13156. {
  13157. return ShmOCPP16Data->OcppConnStatus;
  13158. }
  13159. void SetOcppConnStatus(uint8_t status)
  13160. {
  13161. ShmOCPP16Data->OcppConnStatus = status;
  13162. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13163. }
  13164. int GetHeartBeatWithNOResponse(void)
  13165. {
  13166. return HeartBeatWithNOResponse;
  13167. }
  13168. void SetHeartBeatWithNOResponse(void)
  13169. {
  13170. HeartBeatWithNOResponse = 0;
  13171. }
  13172. void GetStartTransactionIdTag(int gun_index)
  13173. {
  13174. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13175. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13176. }
  13177. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13178. {
  13179. char ch;
  13180. FILE *fptr1;
  13181. int temptransactionId;
  13182. char str[100]={0};
  13183. temptransactionId = 0;
  13184. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13185. {
  13186. DEBUG_INFO("IdTag is empty.\n");
  13187. return temptransactionId;
  13188. }
  13189. /*------ Read the file ----------------*/
  13190. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13191. if (!fptr1)
  13192. {
  13193. DEBUG_INFO("QueueTransactionId file open error.\n");
  13194. //printf(" File not found or unable to open the input file!!\n");
  13195. return temptransactionId;
  13196. }
  13197. ch=fgetc(fptr1);
  13198. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13199. rewind(fptr1);
  13200. if(ch!=EOF)
  13201. {
  13202. // printf("%c",ch);
  13203. while (fgets(str, 100, fptr1) != NULL)
  13204. {
  13205. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13206. if(str[0]=='\0')
  13207. {
  13208. break;
  13209. }
  13210. char *revbuf[8] = {0}; //存放分割後的子字串
  13211. int num = 0;//分割後子字串的個數
  13212. DEBUG_INFO("str: %s\n", str);
  13213. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13214. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13215. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13216. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13217. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13218. {
  13219. if(isStopTransaction)
  13220. {
  13221. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13222. {
  13223. temptransactionId = atoi(revbuf[2]);
  13224. break;
  13225. }
  13226. }
  13227. else
  13228. {
  13229. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13230. {
  13231. temptransactionId = atoi(revbuf[2]);
  13232. break;
  13233. }
  13234. }
  13235. }
  13236. }
  13237. }
  13238. else
  13239. DEBUG_INFO("EOF\n");
  13240. fclose(fptr1);
  13241. /*------- End of reading ---------------*/
  13242. return temptransactionId;
  13243. }
  13244. void SetTransactionIdZero(int transactionId)
  13245. {
  13246. char ch;
  13247. FILE *fptr1, *fptr2;
  13248. int temptransactionId = 0;
  13249. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13250. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13251. if (!fptr1)
  13252. {
  13253. //printf(" File not found or unable to open the input file!!\n");
  13254. return ;
  13255. }
  13256. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13257. if (!fptr2)
  13258. {
  13259. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13260. fclose(fptr1);
  13261. return ;
  13262. }
  13263. ch=fgetc(fptr1);
  13264. rewind(fptr1);
  13265. if(ch!=EOF)
  13266. {
  13267. // copy all contents to the temporary file except the specific line
  13268. while (fgets(str, 100, fptr1) != NULL)
  13269. {
  13270. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13271. if(str[0]=='\0')
  13272. {
  13273. break;
  13274. }
  13275. char *revbuf[8] = {0};
  13276. int num = 0;
  13277. strcpy(strtemp, str);
  13278. splitstring(str,",",revbuf,&num);
  13279. if(revbuf[2][0] != '\0')
  13280. {
  13281. temptransactionId = atoi(revbuf[2]);
  13282. if(transactionId != temptransactionId)
  13283. {
  13284. fprintf(fptr2, "%s\n", strtemp);
  13285. }
  13286. }
  13287. }
  13288. }
  13289. fclose(fptr1);
  13290. fclose(fptr2);
  13291. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13292. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13293. /*------ Read the file ----------------*/
  13294. }
  13295. int InternetDisconnect(void)
  13296. {
  13297. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13298. }
  13299. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13300. void storeTempStopTransaction(int gun_index)
  13301. {
  13302. char guid[37]={0};
  13303. int tempIndex = 0;
  13304. DEBUG_INFO("storeTempStopTransaction...\n");
  13305. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13306. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13307. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13308. if(gunType[gun_index] == 'J')
  13309. {
  13310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13311. {
  13312. tempIndex = ((gun_index==2) ? 1: 0);
  13313. }
  13314. else
  13315. {
  13316. tempIndex = gun_index;
  13317. }
  13318. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13319. {
  13320. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13321. {
  13322. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13323. }
  13324. }// END OF CHAdeMO_QUANTITY
  13325. }
  13326. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13327. {
  13328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13329. {
  13330. tempIndex = ((gun_index==2) ? 1: 0);
  13331. }
  13332. else
  13333. {
  13334. tempIndex = gun_index;
  13335. }
  13336. for (int index = 0; index < CCS_QUANTITY; index++)
  13337. {
  13338. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13339. {
  13340. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13341. }
  13342. }// END OF CCS_QUANTITY
  13343. }
  13344. else if(gunType[gun_index] == 'G')
  13345. {
  13346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13347. {
  13348. tempIndex = ((gun_index==2) ? 1: 0);
  13349. }
  13350. else
  13351. {
  13352. tempIndex = gun_index;
  13353. }
  13354. for (int index = 0; index < GB_QUANTITY; index++)
  13355. {
  13356. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13357. {
  13358. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13359. }
  13360. }// END OF GB_QUANTITY
  13361. }
  13362. else
  13363. {
  13364. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13365. {
  13366. tempIndex = 2;
  13367. }
  13368. else
  13369. {
  13370. tempIndex = gun_index;
  13371. }
  13372. for (int index = 0; index < AC_QUANTITY; index++)
  13373. {
  13374. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13375. {
  13376. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13377. }
  13378. }// END OF AC_QUANTITY
  13379. }
  13380. //Stop Transaction Time
  13381. struct timeval tmnow;
  13382. struct tm *tm;
  13383. char buf[28];//, usec_buf[6];
  13384. gettimeofday(&tmnow, NULL);
  13385. time_t t;
  13386. t = time(NULL);
  13387. /*UTC time and date*/
  13388. tm = gmtime(&t);
  13389. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13391. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13393. random_uuid(guid);
  13394. /***********************************transactionData******************************************************/
  13395. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13397. //=================================
  13398. //1. Transaction_Begin
  13399. //=================================
  13400. //============================== Energy.Active.Import.Interval ===========================================
  13401. //idx_sample=0;
  13402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13405. 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*/]);
  13406. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13407. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13408. {
  13409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13410. }
  13411. else
  13412. {
  13413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13414. }
  13415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13417. //=================================
  13418. //2. Transaction_End
  13419. //=================================
  13420. //2.1====================================== Current.Import L1 ==============================================
  13421. //idx_sample=1;
  13422. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13423. if(gunType[gun_index] == 'J')
  13424. {
  13425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13426. {
  13427. tempIndex = ((gun_index==2) ? 1: 0);
  13428. }
  13429. else
  13430. {
  13431. tempIndex = gun_index;
  13432. }
  13433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13434. {
  13435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13436. {
  13437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13438. }
  13439. }// End of for CHAdeMO_QUANTITY
  13440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13441. }
  13442. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13443. {
  13444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13445. {
  13446. tempIndex = ((gun_index==2) ? 1: 0);
  13447. }
  13448. else
  13449. {
  13450. tempIndex = gun_index;
  13451. }
  13452. for (int index = 0; index < CCS_QUANTITY; index++)
  13453. {
  13454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13455. {
  13456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13457. }
  13458. }// End of for CCS_QUANTITY
  13459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13460. }
  13461. else if(gunType[gun_index] == 'G')
  13462. {
  13463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13464. {
  13465. tempIndex = ((gun_index==2) ? 1: 0);
  13466. }
  13467. else
  13468. {
  13469. tempIndex = gun_index;
  13470. }
  13471. for (int index = 0; index < GB_QUANTITY; index++)
  13472. {
  13473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13474. {
  13475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13476. }
  13477. }// End of for GB_QUANTITY
  13478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13479. }
  13480. else
  13481. {
  13482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13483. {
  13484. tempIndex = 2;
  13485. }
  13486. else
  13487. {
  13488. tempIndex = gun_index;
  13489. }
  13490. for (int index = 0; index < AC_QUANTITY; index++)
  13491. {
  13492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13493. {
  13494. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13495. }
  13496. }// End of for AC_QUANTITY
  13497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13498. }
  13499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13502. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13505. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13506. //idx_sample=2;
  13507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13508. if(gunType[gun_index] == 'J')
  13509. {
  13510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13511. {
  13512. tempIndex = ((gun_index==2) ? 1: 0);
  13513. }
  13514. else
  13515. {
  13516. tempIndex = gun_index;
  13517. }
  13518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13519. {
  13520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13521. {
  13522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13523. }
  13524. }// END OF CHAdeMO_QUANTITY
  13525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13526. }
  13527. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13528. {
  13529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13530. {
  13531. tempIndex = ((gun_index==2) ? 1: 0);
  13532. }
  13533. else
  13534. {
  13535. tempIndex = gun_index;
  13536. }
  13537. for (int index = 0; index < CCS_QUANTITY; index++)
  13538. {
  13539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13540. {
  13541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13542. }
  13543. }// END OF CCS_QUANTITY
  13544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13545. }
  13546. else if(gunType[gun_index] == 'G')
  13547. {
  13548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13549. {
  13550. tempIndex = ((gun_index==2) ? 1: 0);
  13551. }
  13552. else
  13553. {
  13554. tempIndex = gun_index;
  13555. }
  13556. for (int index = 0; index < GB_QUANTITY; index++)
  13557. {
  13558. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13559. {
  13560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13561. }
  13562. }// END OF GB_QUANTITY
  13563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13564. }
  13565. else
  13566. {
  13567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13568. {
  13569. tempIndex = 2;
  13570. }
  13571. else
  13572. {
  13573. tempIndex = gun_index;
  13574. }
  13575. for (int index = 0; index < AC_QUANTITY; index++)
  13576. {
  13577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13578. {
  13579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13580. }
  13581. }// END OF AC_QUANTITY
  13582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13583. }
  13584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13587. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13590. //2.3====================================== Power.Active.Import =========================================
  13591. //idx_sample=3;
  13592. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13593. if(gunType[gun_index] == 'J')
  13594. {
  13595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13596. {
  13597. tempIndex = ((gun_index==2) ? 1: 0);
  13598. }
  13599. else
  13600. {
  13601. tempIndex = gun_index;
  13602. }
  13603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13604. {
  13605. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13606. {
  13607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13608. }
  13609. } // End for CHAdeMO_QUANTITY
  13610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13611. }
  13612. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13613. {
  13614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13615. {
  13616. tempIndex = ((gun_index==2) ? 1: 0);
  13617. }
  13618. else
  13619. {
  13620. tempIndex = gun_index;
  13621. }
  13622. for (int index = 0; index < CCS_QUANTITY; index++)
  13623. {
  13624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13625. {
  13626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13627. }
  13628. } // END for CCS_QUANTITY
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13630. }
  13631. else if(gunType[gun_index] == 'G')
  13632. {
  13633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13634. {
  13635. tempIndex = ((gun_index==2) ? 1: 0);
  13636. }
  13637. else
  13638. {
  13639. tempIndex = gun_index;
  13640. }
  13641. for (int index = 0; index < GB_QUANTITY; index++)
  13642. {
  13643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13644. {
  13645. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13646. }
  13647. }// END for GB_QUANTITY
  13648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13649. }
  13650. else
  13651. {
  13652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13653. {
  13654. tempIndex = 2;
  13655. }
  13656. else
  13657. {
  13658. tempIndex = gun_index;
  13659. }
  13660. for (int index = 0; index < AC_QUANTITY; index++)
  13661. {
  13662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13663. {
  13664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13665. }
  13666. } // END for AC_QUANTITY
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13668. }
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13672. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13675. //2.4====================================== Voltage L1 ====================================================
  13676. //idx_sample=4;
  13677. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13678. if(gunType[gun_index] == 'J')
  13679. {
  13680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13681. {
  13682. tempIndex = ((gun_index==2) ? 1: 0);
  13683. }
  13684. else
  13685. {
  13686. tempIndex = gun_index;
  13687. }
  13688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13689. {
  13690. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13691. {
  13692. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13693. }
  13694. } // END OF FOR CHAdeMO_QUANTITY
  13695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13696. }
  13697. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13698. {
  13699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13700. {
  13701. tempIndex = ((gun_index==2) ? 1: 0);
  13702. }
  13703. else
  13704. {
  13705. tempIndex = gun_index;
  13706. }
  13707. for (int index = 0; index < CCS_QUANTITY; index++)
  13708. {
  13709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13710. {
  13711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13712. }
  13713. } // END OF FOR CCS_QUANTITY
  13714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13715. }
  13716. else if(gunType[gun_index] == 'G')
  13717. {
  13718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13719. {
  13720. tempIndex = ((gun_index==2) ? 1: 0);
  13721. }
  13722. else
  13723. {
  13724. tempIndex = gun_index;
  13725. }
  13726. for (int index = 0; index < GB_QUANTITY; index++)
  13727. {
  13728. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13729. {
  13730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13731. }
  13732. } // END OF FOR GB_QUANTITY
  13733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13734. }
  13735. else
  13736. {
  13737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13738. {
  13739. tempIndex = 2;
  13740. }
  13741. else
  13742. {
  13743. tempIndex = gun_index;
  13744. }
  13745. for (int index = 0; index < AC_QUANTITY; index++)
  13746. {
  13747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13748. {
  13749. 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
  13750. }
  13751. } // END OF FOR AC_QUANTITY
  13752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13753. }
  13754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13757. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13760. //2.5============================================== SoC =========================================================
  13761. //idx_sample=5;
  13762. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13763. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13764. {
  13765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13766. {
  13767. tempIndex = ((gun_index==2) ? 1: 0);
  13768. }
  13769. else
  13770. {
  13771. tempIndex = gun_index;
  13772. }
  13773. if(gunType[gun_index] == 'J')
  13774. {
  13775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13776. {
  13777. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13778. {
  13779. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13780. }
  13781. }
  13782. }
  13783. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13784. {
  13785. for (int index = 0; index < CCS_QUANTITY; index++)
  13786. {
  13787. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13788. {
  13789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13790. }
  13791. }
  13792. }
  13793. else if(gunType[gun_index] == 'G')
  13794. {
  13795. for (int index = 0; index < GB_QUANTITY; index++)
  13796. {
  13797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13798. {
  13799. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13800. }
  13801. }
  13802. }
  13803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13809. } // END FOR DC CASE
  13810. //2.6====================================== Current.Import L2 ==============================================
  13811. // idx_sample=6;
  13812. // AC 3 phase L2 current
  13813. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13814. {
  13815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13816. {
  13817. tempIndex = 2;
  13818. }
  13819. else
  13820. {
  13821. tempIndex = gun_index;
  13822. }
  13823. for (int index = 0; index < AC_QUANTITY; index++)
  13824. {
  13825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13826. {
  13827. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13828. }
  13829. }// End of for AC_QUANTITY
  13830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13831. }
  13832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13837. //2.7====================================== Current.Import L3 ==============================================
  13838. // idx_sample=7;
  13839. // AC 3 phase L3 current
  13840. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13841. {
  13842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13843. {
  13844. tempIndex = 2;
  13845. }
  13846. else
  13847. {
  13848. tempIndex = gun_index;
  13849. }
  13850. for (int index = 0; index < AC_QUANTITY; index++)
  13851. {
  13852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13853. {
  13854. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13855. }
  13856. }// End of for AC_QUANTITY
  13857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13858. }
  13859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13864. //2.9====================================== Voltage L2 ====================================================
  13865. //idx_sample=8;
  13866. // AC 3 phase L2 volatge
  13867. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13868. {
  13869. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13870. {
  13871. tempIndex = 2;
  13872. }
  13873. else
  13874. {
  13875. tempIndex = gun_index;
  13876. }
  13877. for (int index = 0; index < AC_QUANTITY; index++)
  13878. {
  13879. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13880. {
  13881. 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
  13882. }
  13883. } // END OF FOR AC_QUANTITY
  13884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13885. }
  13886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13891. //2.10====================================== Voltage L3 ====================================================
  13892. //idx_sample=9;
  13893. // AC 3 phase L3 volatge
  13894. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13895. {
  13896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13897. {
  13898. tempIndex = 2;
  13899. }
  13900. else
  13901. {
  13902. tempIndex = gun_index;
  13903. }
  13904. for (int index = 0; index < AC_QUANTITY; index++)
  13905. {
  13906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13907. {
  13908. 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
  13909. }
  13910. } // END OF FOR AC_QUANTITY
  13911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13912. }
  13913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13918. //======================================== Message create ==============================================
  13919. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13920. {
  13921. 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\"}]}]}]"
  13922. ,gun_index+1
  13923. ,MESSAGE_TYPE_CALL
  13924. ,guid
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13929. ,"PowerLoss"
  13930. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13973. );
  13974. }
  13975. else
  13976. {
  13977. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13978. {
  13979. 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\"}]}]}]"
  13980. ,gun_index+1
  13981. ,MESSAGE_TYPE_CALL
  13982. ,guid
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13987. ,"PowerLoss"
  13988. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14024. );
  14025. }
  14026. else
  14027. {
  14028. 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\"}]}]}]"
  14029. ,gun_index+1
  14030. ,MESSAGE_TYPE_CALL
  14031. ,guid
  14032. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14033. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14034. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14036. ,"PowerLoss"
  14037. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14046. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14047. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14048. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14049. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14050. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14051. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14054. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14088. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14089. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14090. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14091. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14092. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14093. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14094. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14095. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14096. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14097. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14098. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14099. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14100. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14101. );
  14102. }
  14103. }
  14104. // Check File "TempStopTransaction" Exist
  14105. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14106. {
  14107. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14108. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14109. }
  14110. else
  14111. {
  14112. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14113. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14114. if(log == NULL)
  14115. {
  14116. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14117. return ;
  14118. }
  14119. else
  14120. {
  14121. fclose(log);
  14122. }
  14123. }
  14124. //Add TempStopTransaction | Update TempStopTransaction
  14125. // open file for writing
  14126. FILE *outfile;
  14127. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14128. //DEBUG_INFO("data = %s\n", queuedata);
  14129. fputs(queuedata, outfile);
  14130. fputs("\n", outfile);
  14131. fclose (outfile);
  14132. }
  14133. void checkTempStopTransaction(int gun_index)
  14134. {
  14135. FILE *fptr1;
  14136. char ch;
  14137. char str[QUEUE_MESSAGE_LENGTH]={0};
  14138. char guid[37]={0};
  14139. char tempdata[65]={0};
  14140. char connectorStr[2]={0};
  14141. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14142. //TempStopTransaction格式: 槍號,StopTransaction封包
  14143. if (!fptr1)
  14144. {
  14145. //printf(" File not found or unable to open the input file!!\n");
  14146. return ;
  14147. }
  14148. ch=fgetc(fptr1);
  14149. //printf(" Now the content of the file %s is : \n",fname);
  14150. rewind(fptr1);
  14151. if(ch!=EOF)
  14152. {
  14153. // copy all contents to the temporary file except the specific line
  14154. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14155. {
  14156. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14157. if(str[0]=='\0')
  14158. {
  14159. break;
  14160. }
  14161. //TempStopTransaction格式: 槍號,StopTransaction封包
  14162. strncpy(connectorStr, str, 1);
  14163. if(atoi(connectorStr) != (gun_index+1))
  14164. {
  14165. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14166. return ;
  14167. }
  14168. //random_uuid(guid);
  14169. strncpy(guid, str+6, 36); //copy guid
  14170. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14171. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14172. {
  14173. DEBUG_INFO("StopTransaction mapitem pass\n");
  14174. }
  14175. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14176. memset(str,0,ARRAY_SIZE(str));
  14177. }
  14178. }
  14179. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14180. fclose(fptr1);
  14181. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14182. }
  14183. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14184. {
  14185. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14186. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14187. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14188. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14189. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14190. }
  14191. int GetWebSocketPingInterval(void)
  14192. {
  14193. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14194. }
  14195. int GetServerSign(void)
  14196. {
  14197. return server_sign;
  14198. }
  14199. void SetServerSign(int value)
  14200. {
  14201. server_sign = value;
  14202. }
  14203. int GetBootNotificationInterval(void)
  14204. {
  14205. return BootNotificationInterval;
  14206. }
  14207. int GetInternetConn(void)
  14208. {
  14209. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14210. }
  14211. void InitialSystemValue(void)
  14212. {
  14213. int connectorIndex = 0;
  14214. //int valueASCII = 0;
  14215. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14216. gunTotalNumber=0;
  14217. SystemInitial = 0;
  14218. localversion=0;
  14219. BootNotificationInterval = 0;
  14220. authorizeRetryTimes = 0;
  14221. GunStatusInterval = 10;
  14222. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14223. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14224. //Hear Beat
  14225. HeartBeatWithNOResponse = 0;
  14226. HeartBeatCountPerHour = 0;
  14227. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14228. FirstHeartBeat = 0;
  14229. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14230. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14231. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14232. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14233. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14234. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14235. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14236. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14237. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14238. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14239. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14240. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14241. memset(gunType, 0, ARRAY_SIZE(gunType));
  14242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14243. {
  14244. //check connector / socket type (index: 8, 9, 10)
  14245. for(int index=7; index <10 ; index++)
  14246. {
  14247. if(index != 8)
  14248. {
  14249. // DC Connector
  14250. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14251. {
  14252. SystemInitial = SystemInitial + 1;
  14253. gunTotalNumber = gunTotalNumber + 1;
  14254. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14255. connectorIndex = connectorIndex + 1;
  14256. }
  14257. }
  14258. else
  14259. {
  14260. // AC Connector
  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. }
  14268. }
  14269. }
  14270. //DEBUG_INFO("DC ...\n");
  14271. }
  14272. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14273. {
  14274. //check connector / socket type (index: 8, 9, 10)
  14275. for(int index=7; index <10 ; index++)
  14276. {
  14277. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14278. {
  14279. SystemInitial = SystemInitial + 1;
  14280. gunTotalNumber = gunTotalNumber + 1;
  14281. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14282. connectorIndex = connectorIndex + 1;
  14283. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14284. }
  14285. }
  14286. }
  14287. //Status && ConnectorPlugIn Setting
  14288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14289. {
  14290. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14291. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14292. }
  14293. for (int index = 0; index < CCS_QUANTITY; index++)
  14294. {
  14295. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14296. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14297. }
  14298. for (int index = 0; index < GB_QUANTITY; index++)
  14299. {
  14300. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14301. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14302. }
  14303. for (int index = 0; index < AC_QUANTITY; index++)
  14304. {
  14305. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14306. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14307. }
  14308. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14309. {
  14310. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14311. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14312. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14313. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14314. }
  14315. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14316. clientTime.Heartbeat=time((time_t*)NULL);
  14317. sleep(1);
  14318. }
  14319. void LWS_Send(char * str)
  14320. {
  14321. //=====================================================
  14322. // Check InternetConn 0: disconnected, 1: connected
  14323. //====================================================
  14324. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14325. {
  14326. DEBUG_INFO("offline now !!!\n");
  14327. return;
  14328. }
  14329. pthread_mutex_lock(&lock_send);
  14330. memset(SendBuffer, 0, SendBufLen);
  14331. sprintf((char *)SendBuffer, "%s", str);
  14332. pthread_mutex_unlock(&lock_send);
  14333. lws_callback_on_writable(wsi_client);
  14334. //lws_service(context, 0);
  14335. //sleep(1);
  14336. }