MessageHandler.c 710 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765
  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 _GetConfiguration_CNT
  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. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_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 uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  78. static int TransactionMessageAttemptsValue = 0;
  79. static int TransactionMessageRetryIntervalValue = 0;
  80. static int TempMeterValueInterval = 0;
  81. static struct OCPPAuthLocalElemet
  82. {
  83. int listVersionInt;
  84. char idTagstr[20];
  85. char parentIdTag[20];
  86. char expiryDate[30];
  87. char idTagstatus[16];
  88. }idTagQuery;
  89. //=============================================
  90. // OCPP HeartBeat Response Not Receive Counts
  91. //============================================
  92. static int HeartBeatWithNOResponse = 0;
  93. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CONNECTOR_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq:1; //bit 0,
  124. unsigned char StatusNotificationConf:1; //bit 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CONNECTOR_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. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = YES;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. 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))
  449. {
  450. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. }
  458. else
  459. {
  460. DEBUG_WARN("Start date parsing error.\r\n");
  461. }
  462. return result;
  463. }
  464. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  465. {
  466. int result = -1;
  467. struct tm tmStart;
  468. struct timeb tbStart;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. 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) &&
  472. (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. tmStart.tm_year -= 1900;
  475. tmStart.tm_mon -= 1;
  476. tbStart.time = mktime(&tmStart);
  477. tbStart.millitm = 0;
  478. tmStop.tm_year -= 1900;
  479. tmStop.tm_mon -= 1;
  480. tbStop.time = mktime(&tmStop);
  481. tbStop.millitm = 0;
  482. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  483. }
  484. return result;
  485. }
  486. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  487. {
  488. FILE *fp;
  489. char profileFileName[128];
  490. char *line = NULL;
  491. size_t len = 0;
  492. time_t CurrentTime;
  493. struct tm *tmComposite;
  494. struct StructChargingProfile maxProfile;
  495. struct StructChargingProfile defaultTxProfile;
  496. struct StructChargingProfile txProfile;
  497. struct StructChargingSchedulePeriod tmpPeriod;
  498. uint8_t limitMax=0;
  499. uint8_t limitDef=0;
  500. uint8_t limitTx=0;
  501. int compositePeriodIdx = 0;
  502. CurrentTime = time(NULL);
  503. tmComposite=localtime(&CurrentTime);
  504. 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);
  505. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  506. compositeProfile->ChargingSchedule.Duration = durationReq;
  507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  508. {
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  512. }
  513. compositeProfile->ChargingProfileId = 0;
  514. compositeProfile->StackLevel = 99 ;
  515. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  516. maxProfile.ChargingProfileId = -1;
  517. defaultTxProfile.ChargingProfileId = -1;
  518. txProfile.ChargingProfileId = -1;
  519. maxProfile.ChargingSchedule.Duration = -1;
  520. defaultTxProfile.ChargingSchedule.Duration = -1;
  521. txProfile.ChargingSchedule.Duration = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search tx profile
  529. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. txProfile.ChargingProfileId = -1;
  540. txProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse txProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. 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) &&
  562. (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))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(txProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("TxProfile found.\n");
  574. else
  575. DEBUG_INFO("TxProfile updated.\n");
  576. // Required item
  577. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. 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++)
  582. {
  583. 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"));
  584. 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")));
  585. 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?
  586. 3:
  587. 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")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)txProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)txProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)txProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. txProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. txProfile.ChargingSchedule.Duration = 86400;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. 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")));
  633. }
  634. else
  635. {
  636. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. txProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(txProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("TxProfile found.\n");
  653. else
  654. DEBUG_INFO("TxProfile updated.\n");
  655. // Required item
  656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. 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++)
  661. {
  662. 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"));
  663. 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")));
  664. 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?
  665. 3:
  666. 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")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)txProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)txProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)txProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. txProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. txProfile.ChargingSchedule.Duration = 86400;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. 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")));
  712. }
  713. else
  714. {
  715. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. txProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(txProfile.ChargingProfileId != -1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("TxProfile not found.\n");*/
  757. }
  758. // Search default tx profile
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  760. if((access(profileFileName, F_OK))==-1)
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  762. if((access(profileFileName, F_OK))!=-1)
  763. {
  764. fp = fopen(profileFileName, "r");
  765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  766. {
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  770. }
  771. defaultTxProfile.ChargingProfileId = -1;
  772. defaultTxProfile.StackLevel = -1;
  773. while(getline(&line, &len, fp) != -1)
  774. {
  775. json_object *obj = NULL;
  776. obj = json_tokener_parse(line);
  777. if(is_error(obj))
  778. {
  779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  780. }
  781. else
  782. {
  783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  785. )
  786. {
  787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  789. )
  790. {
  791. struct tm tmFrom, tmTo;
  792. struct timeb tbFrom, tbTo;
  793. 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) &&
  794. (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))
  795. {
  796. tmFrom.tm_year -= 1900;
  797. tmFrom.tm_mon -= 1;
  798. tbFrom.time = mktime(&tmFrom);
  799. tmTo.tm_year -= 1900;
  800. tmTo.tm_mon -= 1;
  801. tbTo.time = mktime(&tmTo);
  802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  803. {
  804. if(defaultTxProfile.ChargingProfileId == -1)
  805. DEBUG_INFO("TxDefaultProfile found.\n");
  806. else
  807. DEBUG_INFO("TxDefaultProfile updated.\n");
  808. // Required item
  809. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  810. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  811. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  812. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  813. 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++)
  814. {
  815. 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"));
  816. 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")));
  817. 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?
  818. 3:
  819. 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")));
  820. }
  821. // Optional item
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  823. {
  824. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  825. }
  826. else
  827. {
  828. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  829. }
  830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  831. {
  832. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  833. }
  834. else
  835. {
  836. sprintf((char*)defaultTxProfile.ValidTo, " ");
  837. }
  838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  839. {
  840. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  841. }
  842. else
  843. {
  844. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  845. }
  846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  847. {
  848. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.TransactionId = -1;
  853. }
  854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  855. {
  856. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  857. }
  858. else
  859. {
  860. defaultTxProfile.ChargingSchedule.Duration = 86400;
  861. }
  862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  863. {
  864. 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")));
  865. }
  866. else
  867. {
  868. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  869. }
  870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  871. {
  872. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  873. }
  874. else
  875. {
  876. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(defaultTxProfile.ChargingProfileId == -1)
  884. DEBUG_INFO("TxDefaultProfile found.\n");
  885. else
  886. DEBUG_INFO("TxDefaultProfile updated.\n");
  887. // Required item
  888. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  889. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  890. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  891. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  892. 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++)
  893. {
  894. 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"));
  895. 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")));
  896. 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?
  897. 3:
  898. 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")));
  899. }
  900. // Optional item
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  902. {
  903. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  904. }
  905. else
  906. {
  907. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  908. }
  909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  910. {
  911. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  912. }
  913. else
  914. {
  915. sprintf((char*)defaultTxProfile.ValidTo, " ");
  916. }
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  918. {
  919. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  920. }
  921. else
  922. {
  923. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  926. {
  927. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.TransactionId = -1;
  932. }
  933. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  934. {
  935. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  936. }
  937. else
  938. {
  939. defaultTxProfile.ChargingSchedule.Duration = 86400;
  940. }
  941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  942. {
  943. 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")));
  944. }
  945. else
  946. {
  947. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  950. {
  951. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  952. }
  953. else
  954. {
  955. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  956. }
  957. }
  958. }
  959. }
  960. json_object_put(obj);
  961. }
  962. fclose(fp);
  963. /*
  964. if(defaultTxProfile.ChargingProfileId != -1)
  965. {
  966. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  967. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  968. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  969. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  970. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  971. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  972. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  973. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  974. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  975. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  976. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  978. {
  979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  980. {
  981. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  982. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  983. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  984. }
  985. }
  986. }
  987. else
  988. DEBUG_INFO("TxDefaultProfile not found.\n");
  989. DEBUG_INFO("------------------------------------\n");*/
  990. }
  991. // Search max profile
  992. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  993. if((access(profileFileName, F_OK))!=-1)
  994. {
  995. fp = fopen(profileFileName, "r");
  996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  997. {
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1001. }
  1002. maxProfile.ChargingProfileId = -1;
  1003. maxProfile.StackLevel = -1;
  1004. while(getline(&line, &len, fp) != -1)
  1005. {
  1006. json_object *obj = NULL;
  1007. obj = json_tokener_parse(line);
  1008. if(is_error(obj))
  1009. {
  1010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1011. }
  1012. else
  1013. {
  1014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1016. )
  1017. {
  1018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. )
  1021. {
  1022. struct tm tmFrom, tmTo;
  1023. struct timeb tbFrom, tbTo;
  1024. 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) &&
  1025. (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))
  1026. {
  1027. tmFrom.tm_year -= 1900;
  1028. tmFrom.tm_mon -= 1;
  1029. tbFrom.time = mktime(&tmFrom);
  1030. tmTo.tm_year -= 1900;
  1031. tmTo.tm_mon -= 1;
  1032. tbTo.time = mktime(&tmTo);
  1033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1034. {
  1035. if(maxProfile.ChargingProfileId == -1)
  1036. DEBUG_INFO("MaxProfile found.\n");
  1037. else
  1038. DEBUG_INFO("MaxProfile updated.\n");
  1039. // Required item
  1040. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1041. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1042. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1043. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1044. 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++)
  1045. {
  1046. 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"));
  1047. 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")));
  1048. 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?
  1049. 3:
  1050. 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")));
  1051. }
  1052. // Optional item
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1054. {
  1055. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1056. }
  1057. else
  1058. {
  1059. sprintf((char*)maxProfile.ValidFrom, " ");
  1060. }
  1061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1062. {
  1063. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1064. }
  1065. else
  1066. {
  1067. sprintf((char*)maxProfile.ValidTo, " ");
  1068. }
  1069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1070. {
  1071. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1072. }
  1073. else
  1074. {
  1075. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1076. }
  1077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1078. {
  1079. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.TransactionId = -1;
  1084. }
  1085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1086. {
  1087. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1088. }
  1089. else
  1090. {
  1091. maxProfile.ChargingSchedule.Duration = 86400;
  1092. }
  1093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1094. {
  1095. 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")));
  1096. }
  1097. else
  1098. {
  1099. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1100. }
  1101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1102. {
  1103. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1104. }
  1105. else
  1106. {
  1107. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if(maxProfile.ChargingProfileId == -1)
  1115. DEBUG_INFO("MaxProfile found.\n");
  1116. else
  1117. DEBUG_INFO("MaxProfile updated.\n");
  1118. // Required item
  1119. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1120. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1121. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1123. 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++)
  1124. {
  1125. 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"));
  1126. 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")));
  1127. 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?
  1128. 3:
  1129. 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")));
  1130. }
  1131. // Optional item
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1133. {
  1134. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)maxProfile.ValidFrom, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1141. {
  1142. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ValidTo, " ");
  1147. }
  1148. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1149. {
  1150. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1151. }
  1152. else
  1153. {
  1154. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1155. }
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1157. {
  1158. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.TransactionId = -1;
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1165. {
  1166. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1167. }
  1168. else
  1169. {
  1170. maxProfile.ChargingSchedule.Duration = 86400;
  1171. }
  1172. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1173. {
  1174. 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")));
  1175. }
  1176. else
  1177. {
  1178. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1179. }
  1180. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1181. {
  1182. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. json_object_put(obj);
  1192. }
  1193. fclose(fp);
  1194. /*
  1195. if(maxProfile.ChargingProfileId !=-1)
  1196. {
  1197. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1198. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1199. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1200. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1201. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1202. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1203. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1204. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1205. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1206. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1207. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1209. {
  1210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1211. {
  1212. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1213. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1214. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1215. }
  1216. }
  1217. }
  1218. else
  1219. DEBUG_INFO("MaxProfile not found.\n");
  1220. DEBUG_INFO("------------------------------------\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. 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);
  1229. 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);
  1230. 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);
  1231. */
  1232. if(txProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(txProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. if(idxPeriod > 0)
  1250. {
  1251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1252. {
  1253. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. 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?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. 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?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1287. {
  1288. if(txProfile.ChargingSchedule.Duration != -1)
  1289. {
  1290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1291. 0:
  1292. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1293. }
  1294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1295. {
  1296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1297. {
  1298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1299. 0:
  1300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1301. if(idxPeriod > 0)
  1302. {
  1303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1304. {
  1305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(txProfile.ChargingSchedule.Duration != -1)
  1314. {
  1315. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1316. 0:
  1317. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1318. }
  1319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1320. {
  1321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1322. {
  1323. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1324. 0:
  1325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /*
  1338. DEBUG_INFO("txProfile after align.\n");
  1339. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1340. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1341. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1342. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1343. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1344. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1345. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1346. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1348. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1349. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. }*/
  1359. }
  1360. if(defaultTxProfile.ChargingProfileId != -1)
  1361. {
  1362. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1380. }
  1381. if(idxPeriod > 0)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. 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?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. 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?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1409. }
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1423. {
  1424. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1427. 0:
  1428. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1440. }
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1469. }
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. /*
  1482. DEBUG_INFO("defaultTxProfile after align.\n");
  1483. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1484. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1485. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1486. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1487. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1488. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1489. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1490. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1491. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1492. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1493. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1497. {
  1498. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1499. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1500. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1501. }
  1502. }
  1503. DEBUG_INFO("------------------------------------\n");*/
  1504. }
  1505. if(maxProfile.ChargingProfileId != -1)
  1506. {
  1507. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. 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?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. 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?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1560. {
  1561. if(maxProfile.ChargingSchedule.Duration != -1)
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1564. 0:
  1565. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1566. }
  1567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1572. 0:
  1573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1574. if(idxPeriod > 0)
  1575. {
  1576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if(maxProfile.ChargingSchedule.Duration != -1)
  1587. {
  1588. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1589. 0:
  1590. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1591. }
  1592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1593. {
  1594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1595. {
  1596. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1597. 0:
  1598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1599. if(idxPeriod > 0)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1602. {
  1603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /*
  1611. DEBUG_INFO("MaxProfile after align.\n");
  1612. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1613. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1614. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1615. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1616. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1617. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1618. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1619. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1620. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1621. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1622. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1623. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1624. {
  1625. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1626. {
  1627. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1628. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1629. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1630. }
  1631. }
  1632. DEBUG_INFO("------------------------------------\n");*/
  1633. }
  1634. /*
  1635. * Merge to conposite schedule
  1636. */
  1637. //DEBUG_INFO("====================================\n");
  1638. // Find each profile period quantity
  1639. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1640. {
  1641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1642. limitMax = idx+1;
  1643. }
  1644. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitDef = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitTx = idx+1;
  1653. }
  1654. // TxProfile found, composite schedule based on it
  1655. if(txProfile.ChargingProfileId != -1)
  1656. {
  1657. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1658. {
  1659. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1660. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1661. (txProfile.ChargingSchedule.Duration > 0))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1668. {
  1669. if((maxProfile.ChargingSchedule.Duration > 0))
  1670. {
  1671. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1673. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1674. }
  1675. else
  1676. {
  1677. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1678. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1679. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1680. }
  1681. }
  1682. if(idxMaxPeriod == (limitMax-1))
  1683. {
  1684. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1685. {
  1686. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1687. {
  1688. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1689. compositePeriodIdx++;
  1690. }
  1691. else
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. }
  1712. if(idxTxPeriod == (limitTx-1))
  1713. {
  1714. if(defaultTxProfile.ChargingProfileId != -1)
  1715. {
  1716. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1717. {
  1718. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1719. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1720. (defaultTxProfile.ChargingSchedule.Duration>0))
  1721. {
  1722. if(maxProfile.ChargingProfileId != -1)
  1723. {
  1724. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1725. {
  1726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1727. {
  1728. if((maxProfile.ChargingSchedule.Duration > 0))
  1729. {
  1730. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1731. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1732. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1733. }
  1734. else
  1735. {
  1736. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1737. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1738. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1739. }
  1740. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1741. {
  1742. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1745. compositePeriodIdx++;
  1746. }
  1747. else
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1775. else if(defaultTxProfile.ChargingProfileId != -1)
  1776. {
  1777. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1778. {
  1779. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1780. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1781. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1782. {
  1783. if(maxProfile.ChargingProfileId != -1)
  1784. {
  1785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1788. {
  1789. if((maxProfile.ChargingSchedule.Duration > 0))
  1790. {
  1791. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1792. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1793. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1794. }
  1795. else
  1796. {
  1797. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1798. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1799. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1800. }
  1801. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1802. {
  1803. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1806. compositePeriodIdx++;
  1807. }
  1808. else
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. }
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1820. {
  1821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. compositePeriodIdx++;
  1823. }
  1824. else
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // Fill other period by MaxProfile
  1833. if(maxProfile.ChargingProfileId != -1)
  1834. {
  1835. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1836. {
  1837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1839. (maxProfile.ChargingSchedule.Duration > 0))
  1840. {
  1841. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1842. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1845. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1849. {
  1850. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1851. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1852. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1853. }
  1854. if(tmpPeriod.Limit != -1)
  1855. {
  1856. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1857. {
  1858. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1861. compositePeriodIdx++;
  1862. }
  1863. else
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1873. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1874. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1875. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1877. {
  1878. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1879. {
  1880. compositeProfile->ChargingProfileId = 1;
  1881. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1882. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1883. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1884. }
  1885. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1886. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1887. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1888. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1889. }
  1890. if(line)
  1891. free(line);
  1892. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1893. }
  1894. //==========================================
  1895. // Init all share memory
  1896. //==========================================
  1897. int InitShareMemory()
  1898. {
  1899. int result = PASS;
  1900. int MeterSMId;
  1901. //creat ShmSysConfigAndInfo
  1902. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1903. {
  1904. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1905. result = FAIL;
  1906. }
  1907. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1908. {
  1909. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1910. result = FAIL;
  1911. }
  1912. else
  1913. {}
  1914. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1915. {
  1916. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1917. result = FAIL;
  1918. }
  1919. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1920. {
  1921. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1922. result = FAIL;
  1923. }
  1924. else
  1925. {}
  1926. //creat ShmPsuData
  1927. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1928. {
  1929. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1930. result = FAIL;
  1931. }
  1932. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1933. {
  1934. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1935. result = FAIL;
  1936. }
  1937. else
  1938. {}
  1939. //creat ShmOCPP16Data
  1940. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1941. {
  1942. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1943. result = FAIL;
  1944. }
  1945. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1946. {
  1947. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1948. result = FAIL;
  1949. }
  1950. else
  1951. {}
  1952. /****************************** For Initial Settings************************************************/
  1953. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1954. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1955. // allocate Configuration memory address
  1956. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1957. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1958. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1959. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1960. //offline MeterValue Interval
  1961. TempMeterValueInterval = 0;
  1962. return result;
  1963. }
  1964. int ProcessShareMemory()
  1965. {
  1966. if(InitShareMemory() == FAIL)
  1967. {
  1968. DEBUG_ERROR("InitShareMemory NG\n");
  1969. if(ShmStatusCodeData!=NULL)
  1970. {
  1971. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1972. }
  1973. sleep(5);
  1974. return FAIL;
  1975. }
  1976. return PASS;
  1977. }
  1978. //---------------------common routine---------------------------//
  1979. int isOFFline(void)
  1980. {
  1981. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1982. {
  1983. if(TempMeterValueInterval >= 2 )
  1984. {
  1985. TempMeterValueInterval = 0;
  1986. return TRUE;
  1987. }
  1988. else
  1989. {
  1990. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1991. return FALSE;
  1992. }
  1993. }
  1994. else
  1995. {
  1996. return FALSE;
  1997. }
  1998. }
  1999. //---------------------------------------------
  2000. // new:
  2001. // enum SYSTEM_STATUS
  2002. // {
  2003. // SYS_MODE_BOOTING = 0,
  2004. // SYS_MODE_IDLE = 1,
  2005. // SYS_MODE_AUTHORIZING = 2,
  2006. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2007. // SYS_MODE_REASSIGN = 4,
  2008. // SYS_MODE_PREPARING = 5,
  2009. // SYS_MODE_PREPARE_FOR_EV = 6,
  2010. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2011. // SYS_MODE_CHARGING = 8,
  2012. // SYS_MODE_TERMINATING = 9,
  2013. // SYS_MODE_COMPLETE = 10,
  2014. // SYS_MODE_ALARM = 11,
  2015. // SYS_MODE_FAULT = 12,
  2016. // SYS_MODE_RESERVATION = 13,
  2017. // SYS_MODE_BOOKING = 14,
  2018. // SYS_MODE_MAINTAIN = 15,
  2019. // SYS_MODE_DEBUG = 16,
  2020. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2021. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2022. // SYS_MODE_UPDATE = 19
  2023. // };
  2024. //
  2025. //
  2026. //-----------------------------------------
  2027. void CheckSystemValue(void)
  2028. {
  2029. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2030. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2031. char filenmae[100]={0};
  2032. char str[100]={0};
  2033. int tempIndex = 0;
  2034. //===============================
  2035. // send Heartbeat
  2036. //===============================
  2037. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2038. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2039. {
  2040. clientTime.Heartbeat=time((time_t*)NULL);
  2041. if(server_sign == TRUE)
  2042. {
  2043. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2044. }
  2045. else
  2046. {
  2047. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2048. }
  2049. }
  2050. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2051. {
  2052. //parameter for test
  2053. sendHeartbeatRequest(0);
  2054. //==============================================
  2055. // Reset Waiting Time
  2056. //==============================================
  2057. HeartBeatWithNOResponse += 1;
  2058. }
  2059. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2060. {
  2061. //===============================
  2062. // CSU Trigger Reset Conf
  2063. //===============================
  2064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2065. {
  2066. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2067. }
  2068. //===============================
  2069. // CSU Trigger Authorize Request
  2070. //===============================
  2071. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2072. {
  2073. sendAuthorizeRequest(0);
  2074. authorizeRetryTimes = authorizeRetryTimes + 1;
  2075. if(authorizeRetryTimes < 3)
  2076. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2077. }
  2078. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2079. {
  2080. authorizeRetryTimes = 0;
  2081. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2082. server_sign = FALSE;
  2083. }
  2084. 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))
  2085. {
  2086. sendAuthorizeRequest(0);
  2087. }
  2088. //===============================
  2089. // CSU Trigger Smart Charging Profilw
  2090. //===============================
  2091. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2092. {
  2093. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2094. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2095. }
  2096. //==============================================
  2097. // Charger start transaction
  2098. //==============================================
  2099. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2100. {
  2101. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2102. sendStartTransactionRequest(gun_index);
  2103. clientTime.StartTransaction = time((time_t*)NULL);
  2104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2105. }
  2106. //==============================================
  2107. // Charger stop transaction
  2108. //==============================================
  2109. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2110. {
  2111. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2112. sendStopTransactionRequest(gun_index);
  2113. clientTime.StopTransaction = time((time_t*)NULL);
  2114. }
  2115. //==============================================
  2116. // Charger status report
  2117. //==============================================
  2118. //--- Check Mode Change ---//
  2119. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2120. if(gunType[gun_index] == 'J')
  2121. {
  2122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2123. {
  2124. tempIndex = ((gun_index==2) ? 1: 0);
  2125. }
  2126. else
  2127. {
  2128. tempIndex = gun_index;
  2129. }
  2130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2133. {
  2134. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2135. {
  2136. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2137. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2138. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2139. statusModeChage[gun_index] = TRUE;
  2140. }
  2141. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2142. {
  2143. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2144. if((access(filenmae,F_OK))!=-1)
  2145. {
  2146. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2147. sprintf(str,"rm -f %s",filenmae);
  2148. system(str);
  2149. }
  2150. }
  2151. #if 1 // for TempStopTransaction
  2152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2153. {
  2154. checkTempStopTransaction(gun_index);
  2155. }
  2156. #endif
  2157. }
  2158. }
  2159. }
  2160. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2161. {
  2162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2163. {
  2164. tempIndex = ((gun_index==2) ? 1: 0);
  2165. }
  2166. else
  2167. {
  2168. tempIndex = gun_index;
  2169. }
  2170. for (int index = 0; index < CCS_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2173. {
  2174. 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]*/ )
  2175. {
  2176. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2177. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2178. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2179. statusModeChage[gun_index] = TRUE;
  2180. }
  2181. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2182. {
  2183. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2184. if((access(filenmae,F_OK))!=-1)
  2185. {
  2186. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2187. sprintf(str,"rm -f %s",filenmae);
  2188. system(str);
  2189. }
  2190. }
  2191. #if 1 // for TempStopTransaction
  2192. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2193. {
  2194. checkTempStopTransaction(gun_index);
  2195. }
  2196. #endif
  2197. }
  2198. }
  2199. }
  2200. else if(gunType[gun_index] == 'G')
  2201. {
  2202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2203. {
  2204. tempIndex = ((gun_index==2) ? 1: 0);
  2205. }
  2206. else
  2207. {
  2208. tempIndex = gun_index;
  2209. }
  2210. for (int index = 0; index < GB_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2213. {
  2214. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2215. {
  2216. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2217. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2218. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2219. statusModeChage[gun_index] = TRUE;
  2220. }
  2221. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2222. {
  2223. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2224. if((access(filenmae,F_OK))!=-1)
  2225. {
  2226. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2227. sprintf(str,"rm -f %s",filenmae);
  2228. system(str);
  2229. }
  2230. }
  2231. #if 1 // for TempStopTransaction
  2232. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2233. {
  2234. checkTempStopTransaction(gun_index);
  2235. }
  2236. #endif
  2237. }
  2238. }
  2239. }
  2240. else if(gunType[gun_index] == 'O')
  2241. {
  2242. tempIndex = gun_index;
  2243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2244. {
  2245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2246. {
  2247. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2248. {
  2249. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2250. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2251. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2252. statusModeChage[gun_index] = TRUE;
  2253. }
  2254. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  2255. {
  2256. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2257. if((access(filenmae,F_OK))!=-1)
  2258. {
  2259. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2260. sprintf(str,"rm -f %s",filenmae);
  2261. system(str);
  2262. }
  2263. }
  2264. #if 1 // for TempStopTransaction
  2265. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2266. {
  2267. checkTempStopTransaction(gun_index);
  2268. }
  2269. #endif
  2270. }
  2271. }
  2272. }
  2273. else
  2274. {
  2275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2276. {
  2277. tempIndex = 2;
  2278. }
  2279. else
  2280. {
  2281. tempIndex = gun_index;
  2282. }
  2283. for (int index = 0; index < AC_QUANTITY; index++)
  2284. {
  2285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2286. {
  2287. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2288. {
  2289. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2290. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2291. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2292. statusModeChage[gun_index] = TRUE;
  2293. }
  2294. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2295. {
  2296. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2297. if((access(filenmae,F_OK))!=-1)
  2298. {
  2299. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2300. sprintf(str,"rm -f %s",filenmae);
  2301. system(str);
  2302. }
  2303. }
  2304. #if 1 // for TempStopTransaction
  2305. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2306. {
  2307. checkTempStopTransaction(gun_index);
  2308. }
  2309. #endif
  2310. }
  2311. }// END
  2312. }
  2313. if(isWebsocketSendable &&
  2314. (((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]) > 10)))) )
  2315. {
  2316. if(SystemInitial > 0)
  2317. SystemInitial -= 1;
  2318. sendStatusNotificationRequest(gun_index);
  2319. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2320. statusModeChage[gun_index] = FALSE;
  2321. }
  2322. //==============================================
  2323. // Meter report
  2324. //==============================================
  2325. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2326. {
  2327. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2328. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2329. }
  2330. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2331. (((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)))
  2332. {
  2333. //check Transaction active
  2334. if(gunType[gun_index] == 'J')
  2335. {
  2336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2337. {
  2338. tempIndex = ((gun_index==2) ? 1: 0);
  2339. }
  2340. else
  2341. {
  2342. tempIndex = gun_index;
  2343. }
  2344. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2345. {
  2346. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2347. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2348. {
  2349. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2350. {
  2351. reqSampleMeter[gun_index] = 1;
  2352. }
  2353. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2354. {
  2355. reqClockAlignMeter[gun_index] = 1;
  2356. }
  2357. }
  2358. }// End for CHAdeMO
  2359. }
  2360. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2361. {
  2362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2363. {
  2364. tempIndex = ((gun_index==2) ? 1: 0);
  2365. }
  2366. else
  2367. {
  2368. tempIndex = gun_index;
  2369. }
  2370. for (int index = 0; index < CCS_QUANTITY; index++)
  2371. {
  2372. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2373. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2374. {
  2375. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2376. {
  2377. reqSampleMeter[gun_index] = 1;
  2378. }
  2379. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2380. {
  2381. reqClockAlignMeter[gun_index] = 1;
  2382. }
  2383. }
  2384. } // End for CCS
  2385. }
  2386. else if(gunType[gun_index] == 'G')
  2387. {
  2388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2389. {
  2390. tempIndex = ((gun_index==2) ? 1: 0);
  2391. }
  2392. else
  2393. {
  2394. tempIndex = gun_index;
  2395. }
  2396. for (int index = 0; index < GB_QUANTITY; index++)
  2397. {
  2398. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2399. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2400. {
  2401. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2402. {
  2403. reqSampleMeter[gun_index] = 1;
  2404. }
  2405. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2406. {
  2407. reqClockAlignMeter[gun_index] = 1;
  2408. }
  2409. }
  2410. }// End for GB
  2411. }
  2412. else if(gunType[gun_index] == 'O')
  2413. {
  2414. tempIndex = gun_index;
  2415. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2416. {
  2417. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2418. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2419. {
  2420. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2421. {
  2422. reqSampleMeter[gun_index] = 1;
  2423. }
  2424. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2425. {
  2426. reqClockAlignMeter[gun_index] = 1;
  2427. }
  2428. }
  2429. }
  2430. }
  2431. else
  2432. {
  2433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2434. {
  2435. tempIndex = 2;
  2436. }
  2437. else
  2438. {
  2439. tempIndex = gun_index;
  2440. }
  2441. for (int index = 0; index < AC_QUANTITY; index++)
  2442. {
  2443. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2444. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2445. {
  2446. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2447. {
  2448. reqSampleMeter[gun_index] = 1;
  2449. }
  2450. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2451. {
  2452. reqClockAlignMeter[gun_index] = 1;
  2453. }
  2454. }
  2455. }//End for AC
  2456. }
  2457. if(reqSampleMeter[gun_index] == 1)
  2458. {
  2459. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2460. storeTempStopTransaction(gun_index);
  2461. }
  2462. else if(reqClockAlignMeter[gun_index] == 1)
  2463. {
  2464. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2465. }
  2466. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2467. sleep(1);
  2468. }
  2469. //==============================================
  2470. // Check Connector reserved
  2471. //==============================================
  2472. //===============================
  2473. // Check if Reserve is expired
  2474. //===============================
  2475. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2476. {
  2477. double diff_t;
  2478. struct tm tp;
  2479. // current time
  2480. time_t t = time(NULL);
  2481. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2482. tp.tm_isdst = -1;
  2483. time_t utc = mktime(&tp);
  2484. diff_t = difftime(utc, t);
  2485. if(diff_t <= 0)
  2486. {
  2487. DEBUG_INFO("reserve expired.\n");
  2488. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2489. }
  2490. }//END OF Check if Reserve is expired
  2491. //==========================================
  2492. // csu trigger FirmwareStatusNotificationReq
  2493. //==========================================
  2494. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2495. {
  2496. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2497. }
  2498. //==========================================
  2499. // csu trigger CancelReservationConf
  2500. //==========================================
  2501. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2502. {
  2503. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2504. }
  2505. //==========================================
  2506. // csu trigger ChangeAvailabilityConf
  2507. //==========================================
  2508. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2509. {
  2510. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2511. }
  2512. //==========================================
  2513. // csu trigger UnlockConnectorConf
  2514. //==========================================
  2515. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2516. {
  2517. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2518. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2519. }
  2520. //==========================================
  2521. // csu trigger ReserveNowConf
  2522. //==========================================
  2523. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2524. {
  2525. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2526. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2527. }
  2528. //==========================================
  2529. // csu trigger DataTransferReq
  2530. //==========================================
  2531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2532. {
  2533. sendDataTransferRequest(gun_index);
  2534. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2535. }
  2536. }
  2537. }
  2538. //==========================================
  2539. // send request routine
  2540. //==========================================
  2541. int sendAuthorizeRequest(int gun_index)
  2542. {
  2543. mtrace();
  2544. int result = FAIL;
  2545. char message[100]={0};
  2546. char guid[37];
  2547. char tempdata[65]={0};
  2548. DEBUG_INFO("sendAuthorizeRequest...\n");
  2549. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2550. //Local Authorize
  2551. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2552. {
  2553. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2554. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2555. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2556. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2557. result = PASS;
  2558. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2559. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2560. authorizeRetryTimes = 0;
  2561. return result;
  2562. }
  2563. 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))||
  2564. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2565. {
  2566. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2567. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2568. {
  2569. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2570. {
  2571. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2572. }
  2573. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2574. {
  2575. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2576. }
  2577. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2578. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2579. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2580. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2581. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2582. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2583. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2584. authorizeRetryTimes = 0;
  2585. return result;
  2586. }
  2587. else
  2588. {
  2589. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2590. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2591. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2592. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2593. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2594. else
  2595. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2596. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2597. result = PASS;
  2598. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2599. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2600. authorizeRetryTimes = 0;
  2601. return result;
  2602. }
  2603. }
  2604. //initailize struct Authorize
  2605. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2606. //get data from shared memory
  2607. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2608. random_uuid(guid);
  2609. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2610. LWS_Send(message);
  2611. sprintf(tempdata, "Authorize,%d", gun_index);
  2612. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2613. {
  2614. result = PASS;
  2615. DEBUG_INFO("Authorize mapItem pass\n");
  2616. }
  2617. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2618. return result;
  2619. }
  2620. int sendBootNotificationRequest(void)
  2621. {
  2622. mtrace();
  2623. int result = FAIL;
  2624. char message[500]={0}, payload[700]={0};
  2625. char guid[37]={0};
  2626. char tempdata[65]={0};
  2627. /*
  2628. int IsGunCharging = FALSE;
  2629. //check Transaction active
  2630. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2631. {
  2632. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2633. {
  2634. IsGunCharging = TRUE;
  2635. }
  2636. }
  2637. for (int index = 0; index < CCS_QUANTITY; index++)
  2638. {
  2639. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2640. {
  2641. IsGunCharging = TRUE;
  2642. }
  2643. }
  2644. for (int index = 0; index < GB_QUANTITY; index++)
  2645. {
  2646. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2647. {
  2648. IsGunCharging = TRUE;
  2649. }
  2650. }
  2651. for (int index = 0; index < AC_QUANTITY; index++)
  2652. {
  2653. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2654. {
  2655. IsGunCharging = TRUE;
  2656. }
  2657. }
  2658. if(IsGunCharging == TRUE)
  2659. {
  2660. server_sign = TRUE;
  2661. return result;
  2662. }
  2663. */
  2664. // Fill BootNotification fields
  2665. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2666. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2667. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2668. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2669. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2670. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2671. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2672. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2673. ShmOCPP16Data->ChargeBoxId
  2674. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2675. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2676. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2677. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2678. ,ShmOCPP16Data->BootNotification.CpIccid
  2679. ,ShmOCPP16Data->BootNotification.CpImsi);
  2680. random_uuid(guid);
  2681. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2682. LWS_Send(message);
  2683. sprintf(tempdata, "BootNotification,0");
  2684. 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*/)
  2685. {
  2686. result = PASS;
  2687. }
  2688. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2689. strcpy(queuedata,message);
  2690. return result;
  2691. }
  2692. int sendDataTransferRequest(int gun_index)
  2693. {
  2694. mtrace();
  2695. char message[1000]={0};
  2696. char guid[37]={0};
  2697. char tempdata[65]={0};
  2698. int result = FAIL;
  2699. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2700. random_uuid(guid);
  2701. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2702. MESSAGE_TYPE_CALL,
  2703. guid,
  2704. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2705. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2706. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2707. LWS_Send(message);
  2708. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2709. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2710. {
  2711. result = PASS;
  2712. DEBUG_INFO("DataTransfer mapItem pass\n");
  2713. }
  2714. return result;
  2715. }
  2716. int sendDiagnosticsStatusNotificationRequest(char *status)
  2717. {
  2718. mtrace();
  2719. int result = FAIL;
  2720. char message[110]={0};
  2721. char guid[37]={0};
  2722. char tempdata[65]={0};
  2723. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2724. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2725. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2726. random_uuid(guid);
  2727. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2728. LWS_SendNow(message);
  2729. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2730. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2731. {
  2732. result = PASS;
  2733. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2734. }
  2735. //#ifdef SystemLogMessage
  2736. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2737. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2738. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2739. //#endif
  2740. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2741. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2742. //record status
  2743. if(strcmp(status,"Idle")==0)
  2744. {
  2745. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2746. }
  2747. else if(strcmp(status,"Uploaded")==0)
  2748. {
  2749. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2750. }
  2751. else if(strcmp(status,"UploadFailed")==0)
  2752. {
  2753. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2754. }
  2755. else if(strcmp(status,"Uploading")==0)
  2756. {
  2757. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2758. }
  2759. return result;
  2760. }
  2761. int sendFirmwareStatusNotificationRequest(char *status)
  2762. {
  2763. mtrace();
  2764. int result = FAIL;
  2765. char message[110]={0};
  2766. char guid[37]={0};
  2767. char tempdata[65]={0};
  2768. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2769. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2770. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2771. random_uuid(guid);
  2772. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2773. LWS_SendNow(message);
  2774. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2775. 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*/)
  2776. {
  2777. result = PASS;
  2778. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2779. }
  2780. //#ifdef SystemLogMessage
  2781. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2782. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2783. //#endif
  2784. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2785. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2786. //record status
  2787. if(strcmp(status,"Downloaded")==0)
  2788. {
  2789. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2790. }
  2791. else if(strcmp(status,"DownloadFailed")==0)
  2792. {
  2793. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2794. }
  2795. else if(strcmp(status,"Downloading")==0)
  2796. {
  2797. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2798. }
  2799. else if(strcmp(status,"Idle")==0)
  2800. {
  2801. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2802. }
  2803. else if(strcmp(status,"InstallationFailed")==0)
  2804. {
  2805. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2806. }
  2807. else if(strcmp(status,"Installing")==0)
  2808. {
  2809. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2810. }
  2811. else if(strcmp(status,"Installed")==0)
  2812. {
  2813. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2814. }
  2815. return result;
  2816. }
  2817. int sendHeartbeatRequest(int gun_index)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[80]={0};
  2822. char guid[37]={0};
  2823. char tempdata[65]={0};
  2824. random_uuid(guid);
  2825. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2826. , MESSAGE_TYPE_CALL
  2827. , guid );
  2828. LWS_Send(message);
  2829. sprintf(tempdata, "Heartbeat,%d", 0);
  2830. 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*/)
  2831. {
  2832. result = PASS;
  2833. }
  2834. return result;
  2835. }
  2836. int sendStartTransactionRequest(int gun_index)
  2837. {
  2838. mtrace();
  2839. int result = FAIL;
  2840. char message[250]={0};
  2841. char guid[37]={0};
  2842. struct timeval tmnow;
  2843. struct tm *tm;
  2844. char buf[28];//, usec_buf[6];
  2845. char tempdata[65]={0};
  2846. int tempIndex = 0;
  2847. DEBUG_INFO("sendStartTransactionRequest...\n");
  2848. gettimeofday(&tmnow, NULL);
  2849. time_t t;
  2850. t = time(NULL);
  2851. /*UTC time and date*/
  2852. tm = gmtime(&t);
  2853. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2854. #if 0 // remove temporally
  2855. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2856. strcat(buf,".");
  2857. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2858. strcat(buf,usec_buf);
  2859. #endif
  2860. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2861. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2862. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2863. // clear StartTransaction Response
  2864. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2865. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2866. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2867. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2868. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2870. if(gunType[gun_index] == 'J')
  2871. {
  2872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2873. {
  2874. tempIndex = ((gun_index==2) ? 1: 0);
  2875. }
  2876. else
  2877. {
  2878. tempIndex = gun_index;
  2879. }
  2880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2881. {
  2882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2883. {
  2884. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2885. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2886. }
  2887. }
  2888. }
  2889. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2890. {
  2891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2892. {
  2893. tempIndex = ((gun_index==2) ? 1: 0);
  2894. }
  2895. else
  2896. {
  2897. tempIndex = gun_index;
  2898. }
  2899. for (int index = 0; index < CCS_QUANTITY; index++)
  2900. {
  2901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2902. {
  2903. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2904. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2905. }
  2906. }
  2907. }
  2908. else if(gunType[gun_index] == 'G')
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < GB_QUANTITY; index++)
  2919. {
  2920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2921. {
  2922. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2923. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2924. }
  2925. }
  2926. }
  2927. else if(gunType[gun_index] == 'O')
  2928. {
  2929. tempIndex = gun_index;
  2930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2931. {
  2932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2933. {
  2934. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  2935. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  2936. }
  2937. }
  2938. }
  2939. else
  2940. {
  2941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2942. {
  2943. tempIndex = 2;
  2944. }
  2945. else
  2946. {
  2947. tempIndex = gun_index;
  2948. }
  2949. for (int index = 0; index < AC_QUANTITY; index++)
  2950. {
  2951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2952. {
  2953. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2954. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2955. }
  2956. }
  2957. }
  2958. random_uuid(guid);
  2959. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2960. {
  2961. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2962. , gun_index +1
  2963. , MESSAGE_TYPE_CALL
  2964. , guid
  2965. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2966. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2967. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2968. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2969. }
  2970. else
  2971. {
  2972. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2973. , gun_index +1
  2974. , MESSAGE_TYPE_CALL
  2975. , guid
  2976. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2977. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2978. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2979. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2980. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2981. }
  2982. #if 1
  2983. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2984. 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*/)
  2985. {
  2986. result = PASS;
  2987. }
  2988. #endif
  2989. strcpy(queuedata, message);
  2990. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2991. return result;
  2992. }
  2993. int sendStatusNotificationRequest(int gun_index)
  2994. {
  2995. mtrace();
  2996. int result = FAIL;
  2997. char message[600]={0};
  2998. char guid[37];
  2999. int currentStatus = 0;
  3000. struct timeval tmnow;
  3001. struct tm *tm;
  3002. char buf[28];//, usec_buf[6];
  3003. char tempdata[65]={0};
  3004. int tempIndex = 0;
  3005. gettimeofday(&tmnow, NULL);
  3006. time_t t;
  3007. t = time(NULL);
  3008. /*UTC time and date*/
  3009. tm = gmtime(&t);
  3010. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3011. #if 0 // remove temporally
  3012. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3013. strcat(buf,".");
  3014. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3015. strcat(buf,usec_buf);
  3016. #endif
  3017. printf("%s",buf);
  3018. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3019. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3020. // it's option
  3021. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3022. /*
  3023. enum _SYSTEM_STATUS
  3024. {
  3025. S_BOOTING = 0,
  3026. S_IDLE, = 1
  3027. S_AUTHORIZING, =2
  3028. S_REASSIGN_CHECK, =3
  3029. S_REASSIGN, =4
  3030. S_PRECHARGE, =5
  3031. S_PREPARING_FOR_EV, =6
  3032. S_PREPARING_FOR_EVSE, =7
  3033. S_CHARGING, =8
  3034. S_TERMINATING, =9
  3035. S_COMPLETE, =10
  3036. S_ALARM, =11
  3037. S_FAULT =12
  3038. }
  3039. */
  3040. //check Transaction active
  3041. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3042. if(gunType[gun_index] == 'J')
  3043. {
  3044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3045. {
  3046. tempIndex = ((gun_index==2) ? 1: 0);
  3047. }
  3048. else
  3049. {
  3050. tempIndex = gun_index;
  3051. }
  3052. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3053. {
  3054. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3055. {
  3056. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3057. {
  3058. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3059. {
  3060. currentStatus = 1; //OCPP Status: Preparing
  3061. }
  3062. else
  3063. {
  3064. currentStatus = 0; //OCPP Status: Available
  3065. }
  3066. }
  3067. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3068. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3069. ) //S_PRECHARGE
  3070. {
  3071. currentStatus = 1; //OCPP Status: Preparing
  3072. }
  3073. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3074. {
  3075. currentStatus = 2; //OCPP Status: Charging
  3076. }
  3077. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3078. {
  3079. currentStatus = 5; //OCPP Status: Finishing
  3080. }
  3081. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3082. {
  3083. currentStatus = 4; //OCPP Status: SuspendedEV
  3084. }
  3085. 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
  3086. {
  3087. currentStatus = 7; //OCPP Status: Unavailable
  3088. }
  3089. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3090. {
  3091. currentStatus = 8; //OCPP Status: Faulted
  3092. }
  3093. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3094. {
  3095. currentStatus = 6; //OCPP Status: Reserved
  3096. }
  3097. } //end of the same index
  3098. }//end of for CHAdeMO_QUANTITY
  3099. }
  3100. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3101. {
  3102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3103. {
  3104. tempIndex = ((gun_index==2) ? 1: 0);
  3105. }
  3106. else
  3107. {
  3108. tempIndex = gun_index;
  3109. }
  3110. for (int index = 0; index < CCS_QUANTITY; index++)
  3111. {
  3112. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3113. {
  3114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3115. {
  3116. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3117. {
  3118. currentStatus = 1; //OCPP Status: Preparing
  3119. }
  3120. else
  3121. {
  3122. currentStatus = 0; //OCPP Status: Available
  3123. }
  3124. }
  3125. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3126. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3127. ) //S_PRECHARGE
  3128. {
  3129. currentStatus = 1; //OCPP Status: Preparing
  3130. }
  3131. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3132. {
  3133. currentStatus = 2; //OCPP Status: Charging
  3134. }
  3135. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3136. {
  3137. currentStatus = 5; //OCPP Status: Finishing
  3138. }
  3139. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3140. {
  3141. currentStatus = 4; //OCPP Status: SuspendedEV
  3142. }
  3143. 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
  3144. {
  3145. currentStatus = 7; //OCPP Status : Unavailable
  3146. }
  3147. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3148. {
  3149. currentStatus = 8; //OCPP Status: Faulted
  3150. }
  3151. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3152. {
  3153. currentStatus = 6; //OCPP Status: Reserved
  3154. }
  3155. } //end of the same index
  3156. } // end of for CCS_QUANTITY
  3157. }
  3158. else if(gunType[gun_index] == 'G')
  3159. {
  3160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3161. {
  3162. tempIndex = ((gun_index==2) ? 1: 0);
  3163. }
  3164. else
  3165. {
  3166. tempIndex = gun_index;
  3167. }
  3168. for (int index = 0; index < GB_QUANTITY; index++)
  3169. {
  3170. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3171. {
  3172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3173. {
  3174. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3175. {
  3176. currentStatus = 1; //OCPP Status: Preparing
  3177. }
  3178. else
  3179. {
  3180. currentStatus = 0; //OCPP Status: Available
  3181. }
  3182. }
  3183. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3184. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3185. ) //S_PRECHARGE
  3186. {
  3187. currentStatus = 1; //OCPP Status: Preparing
  3188. }
  3189. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3190. {
  3191. currentStatus = 2; //OCPP Status: Charging
  3192. }
  3193. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3194. {
  3195. currentStatus = 5; //OCPP Status: Finishing
  3196. }
  3197. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3198. {
  3199. currentStatus = 4; //OCPP Status: SuspendedEV
  3200. }
  3201. 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
  3202. {
  3203. currentStatus = 7; //OCPP Status: Unavailable
  3204. }
  3205. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3206. {
  3207. currentStatus = 8; //OCPP Status: Faulted
  3208. }
  3209. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3210. {
  3211. currentStatus = 6; //OCPP Status: Reserved
  3212. }
  3213. } //end of the same index
  3214. } // end of for GB_QUANTITY
  3215. }
  3216. else if(gunType[gun_index] == 'O')
  3217. {
  3218. tempIndex = gun_index;
  3219. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3220. {
  3221. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3222. {
  3223. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3224. {
  3225. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3226. {
  3227. currentStatus = 1; //OCPP Status: Preparing
  3228. }
  3229. else
  3230. {
  3231. currentStatus = 0; //OCPP Status: Available
  3232. }
  3233. }
  3234. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3235. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3236. ) //S_PRECHARGE
  3237. {
  3238. currentStatus = 1; //OCPP Status: Preparing
  3239. }
  3240. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3241. {
  3242. currentStatus = 2; //OCPP Status: Charging
  3243. }
  3244. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3245. {
  3246. currentStatus = 5; //OCPP Status: Finishing
  3247. }
  3248. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3249. {
  3250. currentStatus = 4; //OCPP Status: SuspendedEV
  3251. }
  3252. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3253. {
  3254. currentStatus = 7; //OCPP Status: Unavailable
  3255. }
  3256. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3257. {
  3258. currentStatus = 8; //OCPP Status: Faulted
  3259. }
  3260. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3261. {
  3262. currentStatus = 6; //OCPP Status: Reserved
  3263. }
  3264. } //end of the same index
  3265. }
  3266. }
  3267. else
  3268. {
  3269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3270. {
  3271. tempIndex = 2;
  3272. }
  3273. else
  3274. {
  3275. tempIndex = gun_index;
  3276. }
  3277. for (int index = 0; index < AC_QUANTITY; index++)
  3278. {
  3279. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3280. {
  3281. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3282. {
  3283. 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))
  3284. {
  3285. currentStatus = 1; //OCPP Status: Preparing
  3286. }
  3287. else
  3288. {
  3289. currentStatus = 0; //OCPP Status: Available
  3290. }
  3291. }
  3292. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3293. {
  3294. currentStatus = 1; //OCPP Status: Preparing
  3295. }
  3296. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3297. {
  3298. currentStatus = 2; //OCPP Status: Charging
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3301. {
  3302. currentStatus = 5; //OCPP Status: Finishing
  3303. }
  3304. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3305. {
  3306. currentStatus = 4; //OCPP Status: SuspendedEV
  3307. }
  3308. 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
  3309. {
  3310. currentStatus = 7; //OCPP Status: Unavailable
  3311. }
  3312. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3313. {
  3314. currentStatus = 8; //OCPP Status: Faulted
  3315. }
  3316. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3317. {
  3318. currentStatus = 6; //OCPP Status: Reserved
  3319. }
  3320. }//end of the same index
  3321. }//end of for AC_QUANTITY
  3322. }
  3323. //it's option
  3324. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3325. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3326. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3327. random_uuid(guid);
  3328. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3329. , MESSAGE_TYPE_CALL
  3330. , guid
  3331. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3332. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3333. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3334. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3335. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3336. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3337. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3338. if((server_sign == TRUE))
  3339. {
  3340. LWS_Send(message);
  3341. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3342. 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*/)
  3343. {
  3344. //DEBUG_ERROR("statusNotification mapitem pass");
  3345. result = PASS;
  3346. }
  3347. }
  3348. else
  3349. {
  3350. result = PASS;
  3351. }
  3352. return result;
  3353. }
  3354. int sendStopTransactionRequest(int gun_index)
  3355. {
  3356. mtrace();
  3357. int result = FAIL;
  3358. //char message[1500]={0};
  3359. char guid[37]={0};
  3360. char tempdata[65]={0};
  3361. int tempIndex = 0;
  3362. char TempStopTransaction[256];
  3363. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3364. //int idx_sample=0;
  3365. DEBUG_INFO("sendStopTransactionRequest \n");
  3366. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3367. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3369. if(gunType[gun_index] == 'J')
  3370. {
  3371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3372. {
  3373. tempIndex = ((gun_index==2) ? 1: 0);
  3374. }
  3375. else
  3376. {
  3377. tempIndex = gun_index;
  3378. }
  3379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3380. {
  3381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3382. {
  3383. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3384. }
  3385. }// END OF CHAdeMO_QUANTITY
  3386. }
  3387. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3388. {
  3389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3390. {
  3391. tempIndex = ((gun_index==2) ? 1: 0);
  3392. }
  3393. else
  3394. {
  3395. tempIndex = gun_index;
  3396. }
  3397. for (int index = 0; index < CCS_QUANTITY; index++)
  3398. {
  3399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3400. {
  3401. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3402. }
  3403. }// END OF CCS_QUANTITY
  3404. }
  3405. else if(gunType[gun_index] == 'G')
  3406. {
  3407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3408. {
  3409. tempIndex = ((gun_index==2) ? 1: 0);
  3410. }
  3411. else
  3412. {
  3413. tempIndex = gun_index;
  3414. }
  3415. for (int index = 0; index < GB_QUANTITY; index++)
  3416. {
  3417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3418. {
  3419. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3420. }
  3421. }// END OF GB_QUANTITY
  3422. }
  3423. else if(gunType[gun_index] == 'O')
  3424. {
  3425. tempIndex = gun_index;
  3426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3427. {
  3428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3429. {
  3430. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3431. }
  3432. }// END OF GB_QUANTITY
  3433. }
  3434. else
  3435. {
  3436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3437. {
  3438. tempIndex = 2;
  3439. }
  3440. else
  3441. {
  3442. tempIndex = gun_index;
  3443. }
  3444. for (int index = 0; index < AC_QUANTITY; index++)
  3445. {
  3446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3447. {
  3448. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3449. }
  3450. }// END OF AC_QUANTITY
  3451. }
  3452. //====================================== Stop Transaction Time =====================================================
  3453. struct timeval tmnow;
  3454. struct tm *tm;
  3455. char buf[28];//, usec_buf[6];
  3456. gettimeofday(&tmnow, NULL);
  3457. time_t t;
  3458. t = time(NULL);
  3459. /*UTC time and date*/
  3460. tm = gmtime(&t);
  3461. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3463. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3464. random_uuid(guid);
  3465. /***********************************transactionData******************************************************/
  3466. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3468. //=================================
  3469. // Transaction_Begin
  3470. //=================================
  3471. //============================================ Energy.Active.Import.Interval ================================
  3472. //idx_sample=0;
  3473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3476. 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*/]);
  3477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3478. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3479. {
  3480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3481. }
  3482. else
  3483. {
  3484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3485. }
  3486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3488. //=================================
  3489. // Transaction_End
  3490. //=================================
  3491. // ================================= Current.Import L1 ===============================================
  3492. //idx_sample=1;
  3493. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3494. if(gunType[gun_index] == 'J')
  3495. {
  3496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3497. {
  3498. tempIndex = ((gun_index==2) ? 1: 0);
  3499. }
  3500. else
  3501. {
  3502. tempIndex = gun_index;
  3503. }
  3504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3505. {
  3506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3507. {
  3508. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3509. }
  3510. }// End of for CHAdeMO_QUANTITY
  3511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3512. }
  3513. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3514. {
  3515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3516. {
  3517. tempIndex = ((gun_index==2) ? 1: 0);
  3518. }
  3519. else
  3520. {
  3521. tempIndex = gun_index;
  3522. }
  3523. for (int index = 0; index < CCS_QUANTITY; index++)
  3524. {
  3525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3526. {
  3527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3528. }
  3529. }// End of for CCS_QUANTITY
  3530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3531. }
  3532. else if(gunType[gun_index] == 'G')
  3533. {
  3534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3535. {
  3536. tempIndex = ((gun_index==2) ? 1: 0);
  3537. }
  3538. else
  3539. {
  3540. tempIndex = gun_index;
  3541. }
  3542. for (int index = 0; index < GB_QUANTITY; index++)
  3543. {
  3544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3545. {
  3546. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3547. }
  3548. }// End of for GB_QUANTITY
  3549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3550. }
  3551. else if(gunType[gun_index] == 'O')
  3552. {
  3553. tempIndex = gun_index;
  3554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3555. {
  3556. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3557. {
  3558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3559. }
  3560. }
  3561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3562. }
  3563. else
  3564. {
  3565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3566. {
  3567. tempIndex = 2;
  3568. }
  3569. else
  3570. {
  3571. tempIndex = gun_index;
  3572. }
  3573. for (int index = 0; index < AC_QUANTITY; index++)
  3574. {
  3575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3576. {
  3577. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3578. }
  3579. }// End of for AC_QUANTITY
  3580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3581. }
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3587. // ================================= Energy.Active.Import.Interval ==============================================
  3588. //idx_sample=2;
  3589. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3590. if(gunType[gun_index] == 'J')
  3591. {
  3592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3593. {
  3594. tempIndex = ((gun_index==2) ? 1: 0);
  3595. }
  3596. else
  3597. {
  3598. tempIndex = gun_index;
  3599. }
  3600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3601. {
  3602. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3603. {
  3604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3605. }
  3606. }// END OF CHAdeMO_QUANTITY
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3608. }
  3609. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3610. {
  3611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3612. {
  3613. tempIndex = ((gun_index==2) ? 1: 0);
  3614. }
  3615. else
  3616. {
  3617. tempIndex = gun_index;
  3618. }
  3619. for (int index = 0; index < CCS_QUANTITY; index++)
  3620. {
  3621. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3622. {
  3623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3624. }
  3625. }// END OF CCS_QUANTITY
  3626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3627. }
  3628. else if(gunType[gun_index] == 'G')
  3629. {
  3630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3631. {
  3632. tempIndex = ((gun_index==2) ? 1: 0);
  3633. }
  3634. else
  3635. {
  3636. tempIndex = gun_index;
  3637. }
  3638. for (int index = 0; index < GB_QUANTITY; index++)
  3639. {
  3640. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3641. {
  3642. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3643. }
  3644. }// END OF GB_QUANTITY
  3645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3646. }
  3647. else if(gunType[gun_index] == 'O')
  3648. {
  3649. tempIndex = gun_index;
  3650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3651. {
  3652. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3653. {
  3654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3655. }
  3656. }
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3658. }
  3659. else
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3662. {
  3663. tempIndex = 2;
  3664. }
  3665. else
  3666. {
  3667. tempIndex = gun_index;
  3668. }
  3669. for (int index = 0; index < AC_QUANTITY; index++)
  3670. {
  3671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3672. {
  3673. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3674. }
  3675. }// END OF AC_QUANTITY
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3677. }
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3683. //=================================== Power.Active.Import ==================================================
  3684. //idx_sample=3;
  3685. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3686. if(gunType[gun_index] == 'J')
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3699. {
  3700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3701. }
  3702. } // End for CHAdeMO_QUANTITY
  3703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3704. }
  3705. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((gun_index==2) ? 1: 0);
  3710. }
  3711. else
  3712. {
  3713. tempIndex = gun_index;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3718. {
  3719. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3720. }
  3721. } // END for CCS_QUANTITY
  3722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3723. }
  3724. else if(gunType[gun_index] == 'G')
  3725. {
  3726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3727. {
  3728. tempIndex = ((gun_index==2) ? 1: 0);
  3729. }
  3730. else
  3731. {
  3732. tempIndex = gun_index;
  3733. }
  3734. for (int index = 0; index < GB_QUANTITY; index++)
  3735. {
  3736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3737. {
  3738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3739. }
  3740. }// END for GB_QUANTITY
  3741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3742. }
  3743. else if(gunType[gun_index] == 'O')
  3744. {
  3745. tempIndex = gun_index;
  3746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3747. {
  3748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3749. {
  3750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3751. }
  3752. }
  3753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3754. }
  3755. else
  3756. {
  3757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3758. {
  3759. tempIndex = 2;
  3760. }
  3761. else
  3762. {
  3763. tempIndex = gun_index;
  3764. }
  3765. for (int index = 0; index < AC_QUANTITY; index++)
  3766. {
  3767. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3768. {
  3769. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3770. }
  3771. } // END for AC_QUANTITY
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3773. }
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3779. //============================ Voltage L1 ====================================
  3780. //idx_sample=4;
  3781. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3782. if(gunType[gun_index] == 'J')
  3783. {
  3784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3785. {
  3786. tempIndex = ((gun_index==2) ? 1: 0);
  3787. }
  3788. else
  3789. {
  3790. tempIndex = gun_index;
  3791. }
  3792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3795. {
  3796. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3797. }
  3798. } // END OF FOR CHAdeMO_QUANTITY
  3799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3800. }
  3801. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3802. {
  3803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3804. {
  3805. tempIndex = ((gun_index==2) ? 1: 0);
  3806. }
  3807. else
  3808. {
  3809. tempIndex = gun_index;
  3810. }
  3811. for (int index = 0; index < CCS_QUANTITY; index++)
  3812. {
  3813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3814. {
  3815. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3816. }
  3817. } // END OF FOR CCS_QUANTITY
  3818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3819. }
  3820. else if(gunType[gun_index] == 'G')
  3821. {
  3822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3823. {
  3824. tempIndex = ((gun_index==2) ? 1: 0);
  3825. }
  3826. else
  3827. {
  3828. tempIndex = gun_index;
  3829. }
  3830. for (int index = 0; index < GB_QUANTITY; index++)
  3831. {
  3832. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3833. {
  3834. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3835. }
  3836. } // END OF FOR GB_QUANTITY
  3837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3838. }
  3839. else if(gunType[gun_index] == 'O')
  3840. {
  3841. tempIndex = gun_index;
  3842. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3843. {
  3844. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3845. {
  3846. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3847. }
  3848. }
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3850. }
  3851. else
  3852. {
  3853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3854. {
  3855. tempIndex = 2;
  3856. }
  3857. else
  3858. {
  3859. tempIndex = gun_index;
  3860. }
  3861. for (int index = 0; index < AC_QUANTITY; index++)
  3862. {
  3863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3864. {
  3865. 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
  3866. }
  3867. } // END OF FOR AC_QUANTITY
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3869. }
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3875. //====================== SoC ================================
  3876. //idx_sample=5;
  3877. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3878. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3879. {
  3880. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3881. {
  3882. tempIndex = ((gun_index==2) ? 1: 0);
  3883. }
  3884. else
  3885. {
  3886. tempIndex = gun_index;
  3887. }
  3888. if(gunType[gun_index] == 'J')
  3889. {
  3890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3891. {
  3892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3893. {
  3894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3895. }
  3896. }
  3897. }
  3898. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3899. {
  3900. for (int index = 0; index < CCS_QUANTITY; index++)
  3901. {
  3902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3903. {
  3904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3905. }
  3906. }
  3907. }
  3908. else if(gunType[gun_index] == 'G')
  3909. {
  3910. for (int index = 0; index < GB_QUANTITY; index++)
  3911. {
  3912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3913. {
  3914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3915. }
  3916. }
  3917. }
  3918. else if(gunType[gun_index] == 'O')
  3919. {
  3920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3921. {
  3922. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3923. {
  3924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  3925. }
  3926. }
  3927. }
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3934. } // END FOR DC CASE
  3935. // ================================= Current.Import L2 ===============================================
  3936. //idx_sample=6;
  3937. // AC 3 phse L2 current
  3938. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3939. {
  3940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3941. {
  3942. tempIndex = 2;
  3943. }
  3944. else
  3945. {
  3946. tempIndex = gun_index;
  3947. }
  3948. for (int index = 0; index < AC_QUANTITY; index++)
  3949. {
  3950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3951. {
  3952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3953. }
  3954. }// End of for AC_QUANTITY
  3955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3956. }
  3957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3962. // ================================= Current.Import L3 ===============================================
  3963. //idx_sample=7;
  3964. // AC 3 phse L3 current
  3965. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3966. {
  3967. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3968. {
  3969. tempIndex = 2;
  3970. }
  3971. else
  3972. {
  3973. tempIndex = gun_index;
  3974. }
  3975. for (int index = 0; index < AC_QUANTITY; index++)
  3976. {
  3977. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3978. {
  3979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3980. }
  3981. }// End of for AC_QUANTITY
  3982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3983. }
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3989. //============================ Voltage L2 ====================================
  3990. //idx_sample=8;
  3991. // AC 3 phse L2 voltage
  3992. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3993. {
  3994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3995. {
  3996. tempIndex = 2;
  3997. }
  3998. else
  3999. {
  4000. tempIndex = gun_index;
  4001. }
  4002. for (int index = 0; index < AC_QUANTITY; index++)
  4003. {
  4004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4005. {
  4006. 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
  4007. }
  4008. } // END OF FOR AC_QUANTITY
  4009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4010. }
  4011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4016. //============================ Voltage L3 ====================================
  4017. //idx_sample=8;
  4018. // AC 3 phse L3 voltage
  4019. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4020. {
  4021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4022. {
  4023. tempIndex = 2;
  4024. }
  4025. else
  4026. {
  4027. tempIndex = gun_index;
  4028. }
  4029. for (int index = 0; index < AC_QUANTITY; index++)
  4030. {
  4031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4032. {
  4033. 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
  4034. }
  4035. } // END OF FOR AC_QUANTITY
  4036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4037. }
  4038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4043. //================================================ Message create ====================================================
  4044. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4045. {
  4046. 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\"}]}]}]"
  4047. ,gun_index+1
  4048. ,MESSAGE_TYPE_CALL
  4049. ,guid
  4050. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4051. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4052. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4053. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4054. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4055. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4088. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4089. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4090. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4091. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  4092. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  4093. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  4094. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  4095. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  4096. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  4097. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  4098. );
  4099. }
  4100. else
  4101. {
  4102. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  4103. {
  4104. 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\"}]}]}]"
  4105. ,gun_index+1
  4106. ,MESSAGE_TYPE_CALL
  4107. ,guid
  4108. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4109. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4110. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4111. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4112. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4113. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4114. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4115. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4116. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4117. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4118. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4119. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4120. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4121. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4122. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4123. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4125. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4126. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4143. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4144. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4145. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4146. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4147. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4148. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4149. );
  4150. }
  4151. else
  4152. {
  4153. 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\"}]}]}]"
  4154. ,gun_index+1
  4155. ,MESSAGE_TYPE_CALL
  4156. ,guid
  4157. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4158. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4159. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4160. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4161. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4162. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4163. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4164. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4165. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4166. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4167. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4168. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4169. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4170. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4171. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4172. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4173. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4174. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4175. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4176. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4177. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4178. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4179. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4180. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4181. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4182. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4184. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4185. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4186. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4189. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4190. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4191. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4192. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4193. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4194. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4195. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4196. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4197. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4198. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4199. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4200. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4201. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4202. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4203. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4204. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4205. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4206. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4207. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4208. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4209. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4210. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4211. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4212. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4213. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4214. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4215. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4216. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4217. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4218. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4219. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4220. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4221. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4222. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4223. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4224. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4225. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4226. );
  4227. }
  4228. }
  4229. #if 1 // for TempStopTransaction
  4230. //Delete TempStopTransaction
  4231. if((access(TempStopTransaction,F_OK))!=-1)
  4232. {
  4233. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4234. }
  4235. #endif
  4236. #if 1
  4237. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4238. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4239. {
  4240. result = PASS;
  4241. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4242. }
  4243. #endif
  4244. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4245. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4246. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4247. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4248. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4249. {
  4250. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4251. }
  4252. //for test
  4253. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4254. return result;
  4255. }
  4256. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4257. {
  4258. mtrace();
  4259. int result = FAIL;
  4260. char guid[37]={0};
  4261. char tempdata[65]={0};
  4262. int tempIndex = 0;
  4263. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4264. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4265. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4266. //set value
  4267. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4268. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : -1);
  4269. random_uuid(guid);
  4270. //UTC Date time
  4271. struct timeval tmnow;
  4272. struct tm *tm;
  4273. char buf[28];//, usec_buf[6];
  4274. gettimeofday(&tmnow, NULL);
  4275. time_t t;
  4276. t = time(NULL);
  4277. /*UTC time and date*/
  4278. tm = gmtime(&t);
  4279. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4281. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4282. //idx_sample=0;
  4283. //********************************(1)Current.Import L1************************************************/
  4284. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4285. if(gunType[gun_index] == 'J')
  4286. {
  4287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4288. {
  4289. tempIndex = ((gun_index==2) ? 1: 0);
  4290. }
  4291. else
  4292. {
  4293. tempIndex = gun_index;
  4294. }
  4295. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4296. {
  4297. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4298. {
  4299. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4300. }
  4301. }
  4302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4303. }
  4304. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4305. {
  4306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4307. {
  4308. tempIndex = ((gun_index==2) ? 1: 0);
  4309. }
  4310. else
  4311. {
  4312. tempIndex = gun_index;
  4313. }
  4314. for (int index = 0; index < CCS_QUANTITY; index++)
  4315. {
  4316. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4317. {
  4318. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4319. }
  4320. }
  4321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4322. }
  4323. else if(gunType[gun_index] == 'G')
  4324. {
  4325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4326. {
  4327. tempIndex = ((gun_index==2) ? 1: 0);
  4328. }
  4329. else
  4330. {
  4331. tempIndex = gun_index;
  4332. }
  4333. for (int index = 0; index < GB_QUANTITY; index++)
  4334. {
  4335. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4336. {
  4337. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4338. }
  4339. }
  4340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4341. }
  4342. else if(gunType[gun_index] == 'O')
  4343. {
  4344. tempIndex = gun_index;
  4345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4346. {
  4347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4348. {
  4349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4350. }
  4351. }
  4352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4353. }
  4354. else
  4355. {
  4356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4357. {
  4358. tempIndex = 2;
  4359. }
  4360. else
  4361. {
  4362. tempIndex = gun_index;
  4363. }
  4364. for (int index = 0; index < AC_QUANTITY; index++)
  4365. {
  4366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4367. {
  4368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4369. }
  4370. }
  4371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4376. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4378. //idx_sample=1;
  4379. //********************************(2)Energy.Active.Import.Register ************************************************/
  4380. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4381. if(gunType[gun_index] == 'J')
  4382. {
  4383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4384. {
  4385. tempIndex = ((gun_index==2) ? 1: 0);
  4386. }
  4387. else
  4388. {
  4389. tempIndex = gun_index;
  4390. }
  4391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4392. {
  4393. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4394. {
  4395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4396. }
  4397. }
  4398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4399. }
  4400. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4401. {
  4402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4403. {
  4404. tempIndex = ((gun_index==2) ? 1: 0);
  4405. }
  4406. else
  4407. {
  4408. tempIndex = gun_index;
  4409. }
  4410. for (int index = 0; index < CCS_QUANTITY; index++)
  4411. {
  4412. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4413. {
  4414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4415. }
  4416. }
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4418. }
  4419. else if(gunType[gun_index] == 'G')
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4422. {
  4423. tempIndex = ((gun_index==2) ? 1: 0);
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < GB_QUANTITY; index++)
  4430. {
  4431. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4432. {
  4433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4434. }
  4435. }
  4436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4437. }
  4438. else if(gunType[gun_index] == 'O')
  4439. {
  4440. tempIndex = gun_index;
  4441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4442. {
  4443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4444. {
  4445. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4446. }
  4447. }
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4449. }
  4450. else
  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[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4465. }
  4466. }
  4467. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4468. }
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4474. //idx_sample=2;
  4475. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4477. if(gunType[gun_index] == 'J')
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4480. {
  4481. tempIndex = ((gun_index==2) ? 1: 0);
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4490. {
  4491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4492. }
  4493. } // END OF FOR CHAdeMO_QUANTITY
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4495. }
  4496. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4497. {
  4498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4499. {
  4500. tempIndex = ((gun_index==2) ? 1: 0);
  4501. }
  4502. else
  4503. {
  4504. tempIndex = gun_index;
  4505. }
  4506. for (int index = 0; index < CCS_QUANTITY; index++)
  4507. {
  4508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4509. {
  4510. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4511. }
  4512. } // END OF CCS_QUANTITY
  4513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4514. }
  4515. else if(gunType[gun_index] == 'G')
  4516. {
  4517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4518. {
  4519. tempIndex = ((gun_index==2) ? 1: 0);
  4520. }
  4521. else
  4522. {
  4523. tempIndex = gun_index;
  4524. }
  4525. for (int index = 0; index < GB_QUANTITY; index++)
  4526. {
  4527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4528. {
  4529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4530. }
  4531. } // END OF GB_QUANTITY
  4532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4533. }
  4534. else if(gunType[gun_index] == 'O')
  4535. {
  4536. tempIndex = gun_index;
  4537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4542. }
  4543. }
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4545. }
  4546. else
  4547. {
  4548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4549. {
  4550. tempIndex = 2;
  4551. }
  4552. else
  4553. {
  4554. tempIndex = gun_index;
  4555. }
  4556. for (int index = 0; index < AC_QUANTITY; index++)
  4557. {
  4558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4559. {
  4560. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4561. }
  4562. }
  4563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4564. }
  4565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4570. //idx_sample=3;
  4571. //********************************(4)Power.Active.Import************************************************/
  4572. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4573. if(gunType[gun_index] == 'J')
  4574. {
  4575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4576. {
  4577. tempIndex = ((gun_index==2) ? 1: 0);
  4578. }
  4579. else
  4580. {
  4581. tempIndex = gun_index;
  4582. }
  4583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4584. {
  4585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4586. {
  4587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4588. }
  4589. } // END OF FOR
  4590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4591. }
  4592. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4593. {
  4594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4595. {
  4596. tempIndex = ((gun_index==2) ? 1: 0);
  4597. }
  4598. else
  4599. {
  4600. tempIndex = gun_index;
  4601. }
  4602. for (int index = 0; index < CCS_QUANTITY; index++)
  4603. {
  4604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4605. {
  4606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4607. }
  4608. }
  4609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4610. }
  4611. else if(gunType[gun_index] == 'G')
  4612. {
  4613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4614. {
  4615. tempIndex = ((gun_index==2) ? 1: 0);
  4616. }
  4617. else
  4618. {
  4619. tempIndex = gun_index;
  4620. }
  4621. for (int index = 0; index < GB_QUANTITY; index++)
  4622. {
  4623. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4624. {
  4625. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4626. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4627. }
  4628. }
  4629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4630. }
  4631. else if(gunType[gun_index] == 'O')
  4632. {
  4633. tempIndex = gun_index;
  4634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4635. {
  4636. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4637. {
  4638. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4640. }
  4641. }
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4643. }
  4644. else
  4645. {
  4646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4647. {
  4648. tempIndex = 2;
  4649. }
  4650. else
  4651. {
  4652. tempIndex = gun_index;
  4653. }
  4654. for (int index = 0; index < AC_QUANTITY; index++)
  4655. {
  4656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4657. {
  4658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4659. }
  4660. }
  4661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4662. }
  4663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4668. //idx_sample=4;
  4669. //***********************************************(5)VOLTAGE L1******************************************************/
  4670. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4671. if(gunType[gun_index] == 'J')
  4672. {
  4673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4674. {
  4675. tempIndex = ((gun_index==2) ? 1: 0);
  4676. }
  4677. else
  4678. {
  4679. tempIndex = gun_index;
  4680. }
  4681. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4682. {
  4683. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4684. {
  4685. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4686. }
  4687. }
  4688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4689. }
  4690. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4691. {
  4692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4693. {
  4694. tempIndex = ((gun_index==2) ? 1: 0);
  4695. }
  4696. else
  4697. {
  4698. tempIndex = gun_index;
  4699. }
  4700. for (int index = 0; index < CCS_QUANTITY; index++)
  4701. {
  4702. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4703. {
  4704. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4705. }
  4706. }
  4707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4708. }
  4709. else if(gunType[gun_index] == 'G')
  4710. {
  4711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4712. {
  4713. tempIndex = ((gun_index==2) ? 1: 0);
  4714. }
  4715. else
  4716. {
  4717. tempIndex = gun_index;
  4718. }
  4719. for (int index = 0; index < GB_QUANTITY; index++)
  4720. {
  4721. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4722. {
  4723. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4724. }
  4725. }
  4726. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4727. }
  4728. else if(gunType[gun_index] == 'O')
  4729. {
  4730. tempIndex = gun_index;
  4731. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4732. {
  4733. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4734. {
  4735. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4736. }
  4737. }
  4738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4739. }
  4740. else
  4741. {
  4742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4743. {
  4744. tempIndex = 2;
  4745. }
  4746. else
  4747. {
  4748. tempIndex = gun_index;
  4749. }
  4750. for (int index = 0; index < AC_QUANTITY; index++)
  4751. {
  4752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4753. {
  4754. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4755. }
  4756. }
  4757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4758. }
  4759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4762. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4764. //***********************************************(6)SOC******************************************************/
  4765. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4766. {
  4767. //idx_sample=5;
  4768. //sampledValue = NULL;
  4769. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4770. {
  4771. tempIndex = ((gun_index==2) ? 1: 0);
  4772. }
  4773. else
  4774. {
  4775. tempIndex = gun_index;
  4776. }
  4777. if(gunType[gun_index] == 'J')
  4778. {
  4779. //tempIndex = ((gun_index==2) ? 1: 0);
  4780. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4781. {
  4782. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4783. {
  4784. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4785. }
  4786. }
  4787. }
  4788. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4789. {
  4790. //tempIndex = ((gun_index==2) ? 1: 0);
  4791. for (int index = 0; index < CCS_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4794. {
  4795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4796. }
  4797. }
  4798. }
  4799. else if(gunType[gun_index] == 'G')
  4800. {
  4801. //tempIndex = ((gun_index==2) ? 1: 0);
  4802. for (int index = 0; index < GB_QUANTITY; index++)
  4803. {
  4804. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4805. {
  4806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4807. }
  4808. }
  4809. }
  4810. else if(gunType[gun_index] == 'O')
  4811. {
  4812. //tempIndex = ((gun_index==2) ? 1: 0);
  4813. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4814. {
  4815. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4816. {
  4817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4818. }
  4819. }
  4820. }
  4821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4824. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4827. }
  4828. //********************************(7)Current.Import L2************************************************/
  4829. // Only for AC 3 phase
  4830. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4831. {
  4832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4833. {
  4834. tempIndex = 2;
  4835. }
  4836. else
  4837. {
  4838. tempIndex = gun_index;
  4839. }
  4840. for (int index = 0; index < AC_QUANTITY; index++)
  4841. {
  4842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4843. {
  4844. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4845. }
  4846. }
  4847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4848. }
  4849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4854. //********************************(8)Current.Import L3************************************************/
  4855. // Only for AC 3 phase
  4856. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4857. {
  4858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4859. {
  4860. tempIndex = 2;
  4861. }
  4862. else
  4863. {
  4864. tempIndex = gun_index;
  4865. }
  4866. for (int index = 0; index < AC_QUANTITY; index++)
  4867. {
  4868. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4869. {
  4870. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4871. }
  4872. }
  4873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4874. }
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4880. //***********************************************(9)VOLTAGE L2******************************************************/
  4881. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4882. {
  4883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4884. {
  4885. tempIndex = 2;
  4886. }
  4887. else
  4888. {
  4889. tempIndex = gun_index;
  4890. }
  4891. for (int index = 0; index < AC_QUANTITY; index++)
  4892. {
  4893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4894. {
  4895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4896. }
  4897. }
  4898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4899. }
  4900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4905. //***********************************************(10)VOLTAGE L3******************************************************/
  4906. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4907. {
  4908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4909. {
  4910. tempIndex = 2;
  4911. }
  4912. else
  4913. {
  4914. tempIndex = gun_index;
  4915. }
  4916. for (int index = 0; index < AC_QUANTITY; index++)
  4917. {
  4918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4919. {
  4920. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4921. }
  4922. }
  4923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4924. }
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4930. // Message create ====================================================================================================
  4931. if(TRUE)
  4932. {
  4933. json_object *MeterValueReq = json_object_new_object();
  4934. json_object *MeterValues = json_object_new_array();
  4935. json_object *sampledValues = json_object_new_array();
  4936. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4937. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4938. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4939. uint8_t idxMeter = 0;
  4940. while(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp) > 0)
  4941. {
  4942. json_object *MeterValue = json_object_new_object();
  4943. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4944. {
  4945. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4946. {
  4947. json_object *sampledValue = json_object_new_object();
  4948. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4949. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4950. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4951. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4952. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4953. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4954. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4955. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4956. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4957. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4958. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4959. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4960. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4961. json_object_array_add(sampledValues, sampledValue);
  4962. }
  4963. }
  4964. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4965. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4966. json_object_array_add(MeterValues, MeterValue);
  4967. idxMeter++;
  4968. }
  4969. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4970. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4971. ,gun_index + 1
  4972. ,MESSAGE_TYPE_CALL
  4973. ,guid
  4974. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4975. json_object_put(MeterValueReq);
  4976. }
  4977. // Put request guid to hash map
  4978. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4979. 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*/)
  4980. {
  4981. result = PASS;
  4982. //DEBUG_INFO("MeterValues mapitem pass\n");
  4983. }
  4984. if((dataType != ReadingContext_Trigger) &&
  4985. (dataType != ReadingContext_Sample_Clock) &&
  4986. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4987. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4988. else
  4989. {
  4990. if(FirstHeartBeat)
  4991. LWS_Send(queuedata +2);
  4992. }
  4993. return result;
  4994. }
  4995. //==========================================
  4996. // send confirm routine
  4997. //==========================================
  4998. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4999. {
  5000. mtrace();
  5001. int result = FAIL;
  5002. char message[100]={0};
  5003. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5005. LWS_Send(message);
  5006. result = TRUE;
  5007. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5008. return result;
  5009. }
  5010. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5011. {
  5012. mtrace();
  5013. int result = FAIL;
  5014. char message[100]={0};
  5015. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5016. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5017. LWS_Send(message);
  5018. result = TRUE;
  5019. return result;
  5020. }
  5021. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. char message[100]={0};
  5026. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5027. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5028. LWS_Send(message);
  5029. result = TRUE;
  5030. return result;
  5031. }
  5032. int sendClearCacheConfirmation(char *uuid,char *payload)
  5033. {
  5034. mtrace();
  5035. int result = FAIL;
  5036. char message[500]={0};
  5037. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5038. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5039. LWS_Send(message);
  5040. return result;
  5041. }
  5042. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5043. {
  5044. mtrace();
  5045. int result = FAIL;
  5046. char message[500]={0};
  5047. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5048. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5049. LWS_Send(message);
  5050. return result;
  5051. }
  5052. int sendDataTransferConfirmation(char *uuid,char *payload)
  5053. {
  5054. mtrace();
  5055. char statusStr[20]={0};
  5056. char dataStr[10]={0};
  5057. char sstr[20]={0};
  5058. int c = 0;
  5059. char *loc;
  5060. int result = FAIL;
  5061. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5062. /**********************status**************************/
  5063. loc = strstr(payload, "status");
  5064. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5065. c = 0;
  5066. while (loc[3+strlen("status")+c] != '\"')
  5067. {
  5068. sstr[c] = loc[3+strlen("status")+c];
  5069. c++;
  5070. }
  5071. sstr[c] = '\0';
  5072. strcpy(statusStr, sstr);
  5073. /**********************data**************************/
  5074. loc = strstr(payload, "data");
  5075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5076. c = 0;
  5077. while (loc[3+strlen("data")+c] != '\"')
  5078. {
  5079. sstr[c] = loc[3+strlen("data")+c];
  5080. c++;
  5081. }
  5082. sstr[c] = '\0';
  5083. strcpy(dataStr, sstr);
  5084. return result;
  5085. }
  5086. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5087. {
  5088. mtrace();
  5089. int result = FAIL;
  5090. char message[1000]={0};
  5091. int CompositeScheduleIndex = 0;
  5092. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5093. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5094. if(nPeriod == 0)
  5095. {
  5096. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5097. {
  5098. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5099. ,MESSAGE_TYPE_CALLRESULT
  5100. ,uuid
  5101. ,payload
  5102. ,connectorIdInt);
  5103. }
  5104. else
  5105. {
  5106. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5107. ,MESSAGE_TYPE_CALLRESULT
  5108. ,uuid
  5109. ,payload
  5110. ,connectorIdInt
  5111. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5112. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5113. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5114. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5115. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5116. }
  5117. }
  5118. else
  5119. {
  5120. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5121. ,MESSAGE_TYPE_CALLRESULT
  5122. ,uuid
  5123. ,payload
  5124. ,connectorIdInt
  5125. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5126. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5127. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5128. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5129. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5130. {
  5131. if (idx_sample == 0)
  5132. {
  5133. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5134. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5135. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5136. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5137. }
  5138. else
  5139. {
  5140. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5141. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5142. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5143. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5144. }
  5145. }
  5146. sprintf(message + strlen(message), "]}}]");
  5147. }
  5148. LWS_Send(message);
  5149. result = TRUE;
  5150. return result;
  5151. }
  5152. int sendGetConfigurationConfirmation(char *uuid)
  5153. {
  5154. mtrace();
  5155. int result = FAIL;
  5156. int MaxKeySupported = 0;
  5157. int sentConfigurationNumber= 0;
  5158. int sentunConfigurationNumber= 0;
  5159. char message[4000]={0};
  5160. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5161. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5162. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5163. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5164. ,MESSAGE_TYPE_CALLRESULT
  5165. ,uuid );
  5166. //configuration key
  5167. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5168. {
  5169. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5170. {
  5171. if (sentConfigurationNumber == 0)
  5172. {
  5173. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5174. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5175. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5176. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5177. }
  5178. else
  5179. {
  5180. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5181. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5182. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5183. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5184. }
  5185. sentConfigurationNumber = sentConfigurationNumber + 1;
  5186. }
  5187. }
  5188. sprintf(message + strlen(message), "]");
  5189. if(UnknownKeynum != 0)
  5190. {
  5191. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5192. //unkown key
  5193. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5194. {
  5195. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5196. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5197. if(sentunConfigurationNumber == 0)
  5198. {
  5199. sprintf(message + strlen(message), "\"%s\""
  5200. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5201. }
  5202. else
  5203. {
  5204. sprintf(message + strlen(message), ",\"%s\""
  5205. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5206. }
  5207. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5208. }
  5209. sprintf(message + strlen(message), "]");
  5210. }
  5211. sprintf(message + strlen(message), "}]");
  5212. LWS_Send(message);
  5213. return result;
  5214. }
  5215. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5216. {
  5217. mtrace();
  5218. int result = FAIL;
  5219. char message[400]={0};
  5220. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5221. if(strcmp(payload,"")==0)
  5222. {
  5223. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5224. }
  5225. else
  5226. {
  5227. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5228. }
  5229. LWS_Send(message);
  5230. result = TRUE;
  5231. return result;
  5232. }
  5233. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5234. {
  5235. mtrace();
  5236. int result = FAIL;
  5237. char message[80]={0};
  5238. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5239. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5240. LWS_Send(message);
  5241. result = TRUE;
  5242. return result;
  5243. }
  5244. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5245. {
  5246. mtrace();
  5247. int result = FAIL;
  5248. char message[80]={0};
  5249. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5250. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5251. LWS_Send(message);
  5252. result = TRUE;
  5253. return result;
  5254. }
  5255. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5256. {
  5257. mtrace();
  5258. int result = FAIL;
  5259. char message[80]={0};
  5260. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5262. LWS_Send(message);
  5263. result = TRUE;
  5264. return result;
  5265. }
  5266. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5267. {
  5268. mtrace();
  5269. int result = FAIL;
  5270. char message[80]={0};
  5271. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5272. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5273. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5274. LWS_Send(message);
  5275. result = TRUE;
  5276. return result;
  5277. }
  5278. int sendResetConfirmation(char *uuid,char *payload)
  5279. {
  5280. mtrace();
  5281. int result = FAIL;
  5282. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5283. char message[80]={0};
  5284. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5285. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5286. LWS_Send(message);
  5287. result = TRUE;
  5288. return result;
  5289. }
  5290. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5291. {
  5292. mtrace();
  5293. int result = FAIL;
  5294. char message[500]={0};
  5295. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5296. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5297. LWS_Send(message);
  5298. result = TRUE;
  5299. return result;
  5300. }
  5301. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5302. {
  5303. mtrace();
  5304. int result = FAIL;
  5305. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5306. char message[80]={0};
  5307. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5309. LWS_Send(message);
  5310. result = TRUE;
  5311. return result;
  5312. }
  5313. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5314. {
  5315. mtrace();
  5316. int result = FAIL;
  5317. char message[80]={0};
  5318. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5320. LWS_Send(message);
  5321. result = TRUE;
  5322. return result;
  5323. }
  5324. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5325. {
  5326. mtrace();
  5327. int result = FAIL;
  5328. char message[80]={0};
  5329. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5330. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5331. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5332. LWS_Send(message);
  5333. result = TRUE;
  5334. return result;
  5335. }
  5336. int sendUpdateFirmwareConfirmation(char *uuid)
  5337. {
  5338. mtrace();
  5339. int result = FAIL;
  5340. char message[60]={0};
  5341. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5342. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5343. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5344. LWS_Send(message);
  5345. result = TRUE;
  5346. return result;
  5347. }
  5348. //==========================================
  5349. // send CallError routine
  5350. //==========================================
  5351. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5352. {
  5353. mtrace();
  5354. char message[220]={0};
  5355. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5356. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5357. LWS_Send(message);
  5358. }
  5359. //==========================================
  5360. // Handle server request routine Start
  5361. //==========================================
  5362. int handleCancelReservationRequest(char *uuid, char *payload)
  5363. {
  5364. mtrace();
  5365. int result = FAIL;
  5366. int gunNO = 0;
  5367. int reservationIdInt = -1;
  5368. char comfirmstr[20];
  5369. DEBUG_INFO("handleCancelReservationRequest...\n");
  5370. json_object *CancelReservation;
  5371. CancelReservation = json_tokener_parse(payload);
  5372. if(!is_error(CancelReservation))
  5373. {
  5374. // Required data
  5375. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5376. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5377. }
  5378. json_object_put(CancelReservation);
  5379. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5380. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5381. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5382. if(reservationIdInt != -1)
  5383. {
  5384. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5385. //check Transaction active
  5386. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5388. {
  5389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5390. {
  5391. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5392. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5393. if(gunType[2] == 'J')
  5394. {
  5395. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5396. }
  5397. else
  5398. {
  5399. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5400. }
  5401. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5402. goto end;
  5403. }
  5404. }
  5405. for (int index = 0; index < CCS_QUANTITY; index++)
  5406. {
  5407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5408. {
  5409. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5410. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5411. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5412. {
  5413. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5414. }
  5415. else
  5416. {
  5417. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5418. }
  5419. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5420. goto end;
  5421. }
  5422. }
  5423. for (int index = 0; index < GB_QUANTITY; index++)
  5424. {
  5425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5426. {
  5427. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5428. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5429. if(gunType[2] == 'G')
  5430. {
  5431. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5432. }
  5433. else
  5434. {
  5435. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5436. }
  5437. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5438. goto end;
  5439. }
  5440. }
  5441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5444. {
  5445. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5446. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5447. if(gunType[2] == 'G')
  5448. {
  5449. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5450. }
  5451. else
  5452. {
  5453. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5454. }
  5455. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5456. goto end;
  5457. }
  5458. }
  5459. for (int index = 0; index < AC_QUANTITY; index++)
  5460. {
  5461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5462. {
  5463. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5464. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5466. {
  5467. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5468. }
  5469. else
  5470. {
  5471. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5472. }
  5473. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5474. goto end;
  5475. }
  5476. }
  5477. }
  5478. //The reservationId does NOT match the reservationId
  5479. sendCancelReservationConfirmation(uuid, comfirmstr);
  5480. end:
  5481. // Fill in ocpp packet uuid
  5482. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5483. return result;
  5484. }
  5485. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5486. {
  5487. mtrace();
  5488. int result = FAIL;
  5489. int gunIndex = 0;
  5490. char typeStr[16]={0};
  5491. char comfirmstr[20];
  5492. int specificId = FALSE;
  5493. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5494. json_object *ChangeAvailability;
  5495. ChangeAvailability = json_tokener_parse(payload);
  5496. if(!is_error(ChangeAvailability))
  5497. {
  5498. // Required data
  5499. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5500. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5501. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5502. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5503. }
  5504. json_object_put(ChangeAvailability);
  5505. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5506. {
  5507. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5508. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5509. }
  5510. else if(gunIndex == 0)
  5511. {
  5512. for(int i=0; i < gunTotalNumber; i++)
  5513. {
  5514. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5515. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5516. }
  5517. }
  5518. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5520. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5521. {
  5522. specificId = TRUE;
  5523. }
  5524. if(specificId == FALSE)
  5525. goto end;
  5526. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5527. {
  5528. //----------------------gunIndex is 0 ------------------------------------------------//
  5529. if(gunIndex == 0)
  5530. {
  5531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5532. {
  5533. for(int i=0; i < gunTotalNumber; i++)
  5534. {
  5535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5536. {
  5537. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5538. {
  5539. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5540. {
  5541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5542. goto end;
  5543. }
  5544. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5545. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5546. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5548. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5549. {
  5550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5551. goto end;
  5552. }
  5553. }
  5554. }//END FOR CHAdeMO_QUANTITY
  5555. for (int index = 0; index < CCS_QUANTITY; index++)
  5556. {
  5557. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5558. {
  5559. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5560. {
  5561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5562. goto end;
  5563. }
  5564. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5565. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5566. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5568. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5569. {
  5570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5571. goto end;
  5572. }
  5573. }
  5574. }//END FOR CCS_QUANTITY
  5575. for (int index = 0; index < GB_QUANTITY; index++)
  5576. {
  5577. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5578. {
  5579. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5580. {
  5581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5582. goto end;
  5583. }
  5584. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5585. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5586. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5589. {
  5590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5591. goto end;
  5592. }
  5593. }
  5594. }// END FOR GB_QUANTITY
  5595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5596. {
  5597. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5598. {
  5599. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5600. {
  5601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5602. goto end;
  5603. }
  5604. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5605. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5609. {
  5610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5611. goto end;
  5612. }
  5613. }
  5614. }// END FOR GENERAL_GUN_QUANTITY
  5615. for (int index = 0; index < AC_QUANTITY; index++)
  5616. {
  5617. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5618. {
  5619. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5620. {
  5621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5622. goto end;
  5623. }
  5624. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5625. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5629. {
  5630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5631. goto end;
  5632. }
  5633. }
  5634. }//END FOR AC_QUANTITY
  5635. }// END FOR gunTotalNumber
  5636. }
  5637. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5638. {
  5639. for(int i=0; i < gunTotalNumber; i++)
  5640. {
  5641. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5642. {
  5643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5644. goto end;
  5645. }
  5646. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5647. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5648. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5651. {
  5652. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5653. goto end;
  5654. }
  5655. }
  5656. }
  5657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5658. goto end;
  5659. }
  5660. //----------------------gunIndex is not 0 ------------------------------------------------//
  5661. //check Transaction active
  5662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5663. {
  5664. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5665. {
  5666. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5667. {
  5668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5669. goto end;
  5670. }
  5671. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5672. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5673. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5676. {
  5677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5678. goto end;
  5679. }
  5680. else
  5681. {
  5682. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5684. goto end;
  5685. }
  5686. }
  5687. }//END FOR CHAdeMO_QUANTITY
  5688. for (int index = 0; index < CCS_QUANTITY; index++)
  5689. {
  5690. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5691. {
  5692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5693. {
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5695. goto end;
  5696. }
  5697. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5698. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5699. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5702. {
  5703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5704. goto end;
  5705. }
  5706. else
  5707. {
  5708. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5710. goto end;
  5711. }
  5712. }
  5713. }//END FOR CCS_QUANTITY
  5714. for (int index = 0; index < GB_QUANTITY; index++)
  5715. {
  5716. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5717. {
  5718. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5719. {
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5721. goto end;
  5722. }
  5723. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5724. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5725. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5728. {
  5729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5730. goto end;
  5731. }
  5732. else
  5733. {
  5734. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5736. goto end;
  5737. }
  5738. }
  5739. }// END FOR GB_QUANTITY
  5740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5741. {
  5742. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5743. {
  5744. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5745. {
  5746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5747. goto end;
  5748. }
  5749. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5750. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5751. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5754. {
  5755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5756. goto end;
  5757. }
  5758. else
  5759. {
  5760. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5762. goto end;
  5763. }
  5764. }
  5765. }// END FOR GENERAL_GUN_QUANTITY
  5766. for (int index = 0; index < AC_QUANTITY; index++)
  5767. {
  5768. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5769. {
  5770. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5771. {
  5772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5773. goto end;
  5774. }
  5775. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5780. {
  5781. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5782. goto end;
  5783. }
  5784. else
  5785. {
  5786. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5788. goto end;
  5789. }
  5790. }
  5791. }//END FOR AC_QUANTITY
  5792. }//END FOR AvailabilityTypeStr[Inoperative]
  5793. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5794. {
  5795. //----------------------gunIndex is 0 ------------------------------------------------//
  5796. if(gunIndex == 0)
  5797. {
  5798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5799. {
  5800. for(int i=0; i < gunTotalNumber; i++)
  5801. {
  5802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5803. {
  5804. 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
  5805. {
  5806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5807. goto end;
  5808. }
  5809. }//END FOR CHAdeMO_QUANTITY
  5810. for (int index = 0; index < CCS_QUANTITY; index++)
  5811. {
  5812. 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
  5813. {
  5814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5815. goto end;
  5816. }
  5817. }//END FOR CCS_QUANTITY
  5818. for (int index = 0; index < GB_QUANTITY; index++)
  5819. {
  5820. 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
  5821. {
  5822. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5824. goto end;
  5825. }
  5826. }// END FOR GB_QUANTITY
  5827. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5828. {
  5829. <<<<<<< HEAD
  5830. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5831. =======
  5832. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5833. >>>>>>> DO360
  5834. {
  5835. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5837. goto end;
  5838. }
  5839. }// END FOR GENERAL_GUN_QUANTITY
  5840. for (int index = 0; index < AC_QUANTITY; index++)
  5841. {
  5842. 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
  5843. {
  5844. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5845. goto end;
  5846. }
  5847. }//END FOR CHAdeMO_QUANTITY
  5848. }// END FOR gunTotalNumber
  5849. }
  5850. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5851. {
  5852. for(int i=0; i < gunTotalNumber; i++)
  5853. {
  5854. for (int index = 0; index < AC_QUANTITY; index++)
  5855. {
  5856. 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
  5857. {
  5858. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5859. goto end;
  5860. }
  5861. }//END FOR CHAdeMO_QUANTITY
  5862. } // END FOR gunTotalNumber
  5863. }
  5864. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5865. goto end;
  5866. }
  5867. //----------------------gunIndex is not 0 ------------------------------------------------//
  5868. //check Transaction active
  5869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5870. {
  5871. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5872. {
  5873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5874. goto end;
  5875. }
  5876. }//END FOR CHAdeMO_QUANTITY
  5877. for (int index = 0; index < CCS_QUANTITY; index++)
  5878. {
  5879. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5880. {
  5881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5882. goto end;
  5883. }
  5884. }//END FOR CCS_QUANTITY
  5885. for (int index = 0; index < GB_QUANTITY; index++)
  5886. {
  5887. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5888. {
  5889. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5890. goto end;
  5891. }
  5892. }// END FOR GB_QUANTITY
  5893. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5894. {
  5895. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5896. {
  5897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5898. goto end;
  5899. }
  5900. }// END FOR GENERAL_GUN_QUANTITY
  5901. for (int index = 0; index < AC_QUANTITY; index++)
  5902. {
  5903. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5904. {
  5905. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5906. goto end;
  5907. }
  5908. }//END FOR AC_QUANTITY
  5909. }//END FOR AvailabilityTypeStr[Operative]
  5910. end:
  5911. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5912. {
  5913. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5914. }
  5915. else
  5916. {
  5917. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5918. }
  5919. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5920. {
  5921. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5922. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5923. }
  5924. else if(gunIndex == 0)
  5925. {
  5926. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5927. {
  5928. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5929. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5930. }
  5931. }
  5932. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5933. return result;
  5934. }
  5935. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5936. {
  5937. mtrace();
  5938. int result = FAIL;
  5939. char keystr[40]={0};
  5940. char valuestr[100]={0};
  5941. char comfirmstr[20]={0};
  5942. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5943. json_object *ChangeConfiguration;
  5944. ChangeConfiguration = json_tokener_parse(payload);
  5945. if(!is_error(ChangeConfiguration))
  5946. {
  5947. // Required data
  5948. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5949. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5950. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5951. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5952. }
  5953. json_object_put(ChangeConfiguration);
  5954. if((uuid==NULL) || (payload ==NULL) )
  5955. {
  5956. DEBUG_ERROR("Payload is null\n");
  5957. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5958. }
  5959. else
  5960. {
  5961. int status = setKeyValue(keystr, valuestr);
  5962. switch(status)
  5963. {
  5964. case ConfigurationStatus_Accepted:
  5965. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5966. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5967. StoreConfigurationTable();
  5968. break;
  5969. case RebootRequired:
  5970. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5971. StoreConfigurationTable();
  5972. break;
  5973. case NotSupported:
  5974. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5975. break;
  5976. case ConfigurationStatus_Rejected:
  5977. default:
  5978. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5979. break;
  5980. }
  5981. }
  5982. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5983. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5984. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5985. {
  5986. ChageWebSocketPingInterval(atoi(valuestr));
  5987. }
  5988. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5989. {
  5990. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5991. }
  5992. return result;
  5993. }
  5994. int handleClearCacheRequest(char *uuid, char *payload)
  5995. {
  5996. mtrace();
  5997. int result = FAIL;
  5998. char comfirmstr[20];
  5999. int fd;
  6000. char rmFileCmd[100]={0};
  6001. struct stat stats;
  6002. DEBUG_INFO("handleClearCacheRequest...\n");
  6003. stat("/Storage/OCPP", &stats);
  6004. // Check for directory existence
  6005. if (S_ISDIR(stats.st_mode) == 1)
  6006. {}
  6007. else
  6008. {
  6009. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6010. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6011. system(rmFileCmd);
  6012. }
  6013. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  6014. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  6015. {
  6016. DEBUG_INFO("AuthorizationCache file exist.\n");
  6017. }
  6018. else
  6019. {
  6020. DEBUG_INFO("AuthorizationCache file not exist\n");
  6021. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  6022. if(log == NULL)
  6023. {
  6024. DEBUG_INFO("AuthorizationCache file is NULL\n");
  6025. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6026. goto end;
  6027. }
  6028. else
  6029. {
  6030. fclose(log);
  6031. }
  6032. }
  6033. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  6034. {
  6035. DEBUG_INFO("open AuthorizationCache file failed\n");
  6036. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6037. }
  6038. else
  6039. {
  6040. DEBUG_INFO("open AuthorizationCache file successful\n");
  6041. ftruncate(fd,0);
  6042. lseek(fd,0,SEEK_SET);
  6043. close(fd);
  6044. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6045. }
  6046. end:
  6047. sendClearCacheConfirmation(uuid, comfirmstr);
  6048. return result;
  6049. }
  6050. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6051. {
  6052. mtrace();
  6053. int result = FAIL;
  6054. int resultRename;
  6055. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6056. char chargingProfilePurposeStr[26]={0};
  6057. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6058. char tempchargingProfilePurposeStr[26]={0};
  6059. char str[100]={0};
  6060. char fname[200]={0};
  6061. char comfirmstr[20]={0};
  6062. char word[1600]={0};
  6063. int clearflag = FALSE;
  6064. int chargingProfileIdIsNULL = FALSE;
  6065. int connectorIsNULL = FALSE;
  6066. int chargingProfilePurposeIsNULL = FALSE;
  6067. int stackLevelIsNULL = FALSE;
  6068. //int GotoEnd = FALSE;
  6069. FILE *fptr1, *fptr2;
  6070. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6071. int n_chargingProfile=0;
  6072. int isEmptyFile = FALSE;
  6073. char sLineWord[1600]={0};
  6074. char chargingProfiles[10][100]={0};
  6075. int ChargeProfileCount = 0;
  6076. int ch;
  6077. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6078. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6079. json_object *ClearChargingProfile;
  6080. ClearChargingProfile = json_tokener_parse(payload);
  6081. if(!is_error(ClearChargingProfile))
  6082. {
  6083. // Optional data
  6084. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6085. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6086. else
  6087. chargingProfileIdIsNULL = TRUE;
  6088. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6089. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6090. else
  6091. connectorIsNULL = TRUE;
  6092. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6093. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6094. else
  6095. chargingProfilePurposeIsNULL = TRUE;
  6096. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6097. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6098. else
  6099. stackLevelIsNULL = TRUE;
  6100. }
  6101. json_object_put(ClearChargingProfile);
  6102. if(connectorIsNULL == FALSE)
  6103. {
  6104. switch(connectorIdInt)
  6105. {
  6106. case 0:
  6107. if(chargingProfilePurposeIsNULL == TRUE)
  6108. {
  6109. int l = 0;
  6110. strcpy(fname, ChargePointMaxProfile_JSON);
  6111. if((access(fname,F_OK))!=-1)
  6112. {
  6113. strcpy(chargingProfiles[l], fname);
  6114. l = l + 1;
  6115. }
  6116. strcpy(fname, TxDefaultProfile_0_JSON);
  6117. if((access(fname,F_OK))!=-1)
  6118. {
  6119. strcpy(chargingProfiles[l], fname);
  6120. l = l + 1;
  6121. }
  6122. ChargeProfileCount = l;
  6123. }
  6124. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6125. {
  6126. strcpy(fname, ChargePointMaxProfile_JSON);
  6127. if((access(fname,F_OK))!=-1)
  6128. {
  6129. strcpy(chargingProfiles[0], fname);
  6130. ChargeProfileCount = 1;
  6131. }
  6132. }
  6133. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6134. {
  6135. strcpy(fname, TxDefaultProfile_0_JSON);
  6136. if((access(fname,F_OK))!=-1)
  6137. {
  6138. strcpy(chargingProfiles[0], fname);
  6139. ChargeProfileCount = 1;
  6140. }
  6141. }
  6142. break;
  6143. default:
  6144. if(chargingProfilePurposeIsNULL == TRUE)
  6145. {
  6146. int m = 0;
  6147. memset(fname, 0, ARRAY_SIZE(fname));
  6148. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6149. if((access(fname,F_OK))!=-1)
  6150. {
  6151. strcpy(chargingProfiles[m], fname);
  6152. m = m + 1;
  6153. }
  6154. memset(fname, 0, ARRAY_SIZE(fname));
  6155. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6156. if((access(fname,F_OK))!=-1)
  6157. {
  6158. strcpy(chargingProfiles[m], fname);
  6159. m = m + 1;
  6160. }
  6161. ChargeProfileCount = m;
  6162. }
  6163. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6164. {
  6165. //strcpy(fname, TxDefaultProfile_1_JSON);
  6166. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6167. if((access(fname,F_OK))!=-1)
  6168. {
  6169. strcpy(chargingProfiles[0], fname);
  6170. ChargeProfileCount = 1;
  6171. }
  6172. }
  6173. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6174. {
  6175. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6176. if((access(fname,F_OK))!=-1)
  6177. {
  6178. strcpy(chargingProfiles[0], fname);
  6179. ChargeProfileCount = 1;
  6180. }
  6181. //strcpy(fname, TxProfile_1_JSON);
  6182. }
  6183. //strcpy(fname, ChargePointMaxProfile_JSON );
  6184. break;
  6185. }
  6186. }
  6187. else // Check all Charging Profiles
  6188. {
  6189. int i = 0;
  6190. char fnametemp[200]={0};
  6191. ChargeProfileCount = 0;
  6192. //Check ChargePointMaxProfile.json exit
  6193. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6194. {
  6195. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6196. i = i + 1;
  6197. }
  6198. //Check TxDefaultProfile_0.json exit
  6199. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6200. {
  6201. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6202. i = i + 1;
  6203. }
  6204. //Check TxDefaultProfile_%d.json
  6205. for(int j=1; j <= gunTotalNumber; j++)
  6206. {
  6207. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6208. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6209. if((access(fnametemp,F_OK))!=-1)
  6210. {
  6211. strcpy(chargingProfiles[i], fnametemp);
  6212. i = i + 1;
  6213. }
  6214. }
  6215. //Check TxProfile_%d.json
  6216. for(int j=1; j <= gunTotalNumber; j++)
  6217. {
  6218. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6219. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6220. if((access(fnametemp,F_OK))!=-1)
  6221. {
  6222. strcpy(chargingProfiles[i], fnametemp);
  6223. i = i + 1;
  6224. }
  6225. }
  6226. ChargeProfileCount = i;
  6227. }// End connectorIsNULL is TRUE
  6228. if(ChargeProfileCount == 0)
  6229. {
  6230. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6231. goto end;
  6232. }
  6233. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6234. {
  6235. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6236. goto end;
  6237. }
  6238. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6239. {
  6240. memset(str, 0, ARRAY_SIZE(str));
  6241. // clear temp file
  6242. sprintf(str,"rm -f %s",temp);
  6243. system(str);
  6244. for(int k=0; k < ChargeProfileCount; k++)
  6245. {
  6246. memset(str, 0, ARRAY_SIZE(str));
  6247. //clear file in C
  6248. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6249. system(str);
  6250. }
  6251. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6252. goto end;
  6253. }
  6254. else if(connectorIsNULL == TRUE)
  6255. {
  6256. for(int k=0; k < ChargeProfileCount; k++)
  6257. {
  6258. fptr1 = fopen(chargingProfiles[k], "r");
  6259. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6260. //Check Charging Profile Count
  6261. while(fscanf(fptr1, "%s", word) != EOF)
  6262. {
  6263. //DEBUG_INFO("word=%s\n",word);
  6264. if(strstr(word, "chargingProfileId")!= NULL)
  6265. {
  6266. //DEBUG_INFO("test chargingProfileId \n");
  6267. n_chargingProfile = n_chargingProfile + 1;
  6268. //DEBUG_INFO("chargingProfileId Found\n");
  6269. }
  6270. }
  6271. rewind(fptr1);
  6272. //search Charging Profile Element
  6273. //int i= 0;
  6274. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6275. {
  6276. json_object *tmpProfilee;
  6277. tmpProfilee = json_tokener_parse(sLineWord);
  6278. if(!is_error(tmpProfilee))
  6279. {
  6280. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6281. {
  6282. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6283. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6284. }
  6285. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6286. {
  6287. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6288. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6289. }
  6290. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6291. {
  6292. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6293. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6294. }
  6295. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6296. {
  6297. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6298. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6299. }
  6300. }
  6301. json_object_put(tmpProfilee);
  6302. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6303. {
  6304. //------- not write to fptr2-------//
  6305. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6306. //clearflag = TRUE;
  6307. }
  6308. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6309. {
  6310. //------- not write to fptr2-------//
  6311. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6312. }
  6313. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6314. {
  6315. //------- not write to fptr2-------//
  6316. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6317. }
  6318. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6319. {
  6320. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6321. }
  6322. else
  6323. {
  6324. fprintf(fptr2, sLineWord);//writing data into file
  6325. }
  6326. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6327. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6328. if(clearflag == TRUE)
  6329. {
  6330. fclose(fptr1);
  6331. fclose(fptr2);
  6332. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6333. system(str);
  6334. // clear temp file
  6335. sprintf(str,"rm -f %s",temp);
  6336. system(str);
  6337. }
  6338. else
  6339. {
  6340. fclose(fptr1);
  6341. fclose(fptr2);
  6342. memset(str, 0, ARRAY_SIZE(str));
  6343. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6344. system(str);
  6345. resultRename = rename(temp, chargingProfiles[k]);
  6346. if(resultRename == 0)
  6347. {
  6348. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6349. }
  6350. else
  6351. {
  6352. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6353. }
  6354. if(comfirmstr[0]== 0)
  6355. {
  6356. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6357. }
  6358. //Check chargingProfile is empty file
  6359. /*------ Read the file ----------------*/
  6360. fptr1=fopen(chargingProfiles[k],"r");
  6361. ch=fgetc(fptr1);
  6362. rewind(fptr1);
  6363. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6364. if(ch!=EOF)
  6365. {
  6366. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6367. {
  6368. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6369. if(sLineWord[0]=='\0')
  6370. {
  6371. isEmptyFile = TRUE;
  6372. break;
  6373. }
  6374. else
  6375. {
  6376. isEmptyFile = FALSE;
  6377. break;
  6378. }
  6379. }
  6380. }
  6381. else
  6382. isEmptyFile = TRUE;
  6383. fclose(fptr1);
  6384. if(isEmptyFile == TRUE)
  6385. {
  6386. memset(str, 0, ARRAY_SIZE(str));
  6387. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6388. system(str);
  6389. }
  6390. }
  6391. }// End of while(int k=0; k < ChargePointCount; k++)
  6392. }
  6393. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6394. {
  6395. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6396. for(int k=0; k < ChargeProfileCount; k++)
  6397. {
  6398. fptr1 = fopen(chargingProfiles[k], "r");
  6399. fptr2 = fopen(temp, "w+");
  6400. //Check Charging Profile Count
  6401. while(fscanf(fptr1, "%s", word) != EOF)
  6402. {
  6403. //DEBUG_INFO("word=%s\n",word);
  6404. if(strstr(word, "chargingProfileId")!= NULL)
  6405. {
  6406. n_chargingProfile = n_chargingProfile + 1;
  6407. }
  6408. }
  6409. rewind(fptr1);
  6410. //search Charging Profile Element
  6411. //int i= 0;
  6412. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6413. {
  6414. json_object *tmpProfilee;
  6415. tmpProfilee = json_tokener_parse(sLineWord);
  6416. if(!is_error(tmpProfilee))
  6417. {
  6418. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6419. {
  6420. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6421. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6422. }
  6423. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6424. {
  6425. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6426. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6427. }
  6428. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6429. {
  6430. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6431. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6432. }
  6433. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6434. {
  6435. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6436. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6437. }
  6438. }
  6439. json_object_put(tmpProfilee);
  6440. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6441. {
  6442. //------- not write to fptr2-------//
  6443. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6444. //clearflag = TRUE;
  6445. }
  6446. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6447. {
  6448. //------- not write to fptr2-------//
  6449. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6450. }
  6451. else if(stackLevelIsNULL == TRUE)
  6452. {
  6453. //Clear Whole File
  6454. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6455. clearflag = TRUE;
  6456. break;
  6457. }
  6458. else
  6459. {
  6460. fprintf(fptr2, sLineWord);//writing data into file
  6461. }
  6462. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6463. }
  6464. if(clearflag == TRUE)
  6465. {
  6466. fclose(fptr1);
  6467. fclose(fptr2);
  6468. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6469. system(str);
  6470. // clear temp file
  6471. sprintf(str,"rm -f %s",temp);
  6472. system(str);
  6473. }
  6474. else
  6475. {
  6476. fclose(fptr1);
  6477. fclose(fptr2);
  6478. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6479. system(str);
  6480. resultRename = rename(temp, chargingProfiles[k]);
  6481. if(resultRename == 0)
  6482. {
  6483. DEBUG_INFO("File ChargingProfile renamed successfully");
  6484. }
  6485. else
  6486. {
  6487. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6488. }
  6489. if(comfirmstr[0]== 0)
  6490. {
  6491. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6492. }
  6493. //Check chargingProfile is empty file
  6494. /*------ Read the file ----------------*/
  6495. fptr1=fopen(chargingProfiles[k],"r");
  6496. ch=fgetc(fptr1);
  6497. rewind(fptr1);
  6498. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6499. if(ch!=EOF)
  6500. {
  6501. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6502. {
  6503. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6504. if(sLineWord[0]=='\0')
  6505. {
  6506. isEmptyFile = TRUE;
  6507. break;
  6508. }
  6509. else
  6510. {
  6511. isEmptyFile = FALSE;
  6512. break;
  6513. }
  6514. }
  6515. }
  6516. else
  6517. isEmptyFile = TRUE;
  6518. fclose(fptr1);
  6519. if(isEmptyFile == TRUE)
  6520. {
  6521. memset(str, 0, ARRAY_SIZE(str));
  6522. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6523. system(str);
  6524. }
  6525. /*------- End of reading ---------------*/
  6526. }
  6527. } // while(int k=0; k < ChargeProfileCount; k++)
  6528. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6529. end:
  6530. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6531. {
  6532. if(connectorIdInt == 0)
  6533. {
  6534. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6535. {
  6536. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6537. }
  6538. }
  6539. else
  6540. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6541. }
  6542. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6543. return result;
  6544. }
  6545. void createFirmwareVersionByDataTransfer(void)
  6546. {
  6547. json_object *FirmwareDataTransfer = json_object_new_object();
  6548. // AC & DC model
  6549. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6550. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6551. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6552. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6553. // DC model
  6554. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6555. {
  6556. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6557. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6558. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6559. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6560. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6561. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6562. }
  6563. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6564. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6565. {
  6566. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6567. }
  6568. // 4G model
  6569. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6570. {
  6571. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6572. }
  6573. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6574. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6575. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6576. json_object_put(FirmwareDataTransfer);
  6577. }
  6578. int handleDataTransferRequest(char *uuid, char *payload)
  6579. {
  6580. mtrace();
  6581. json_object *response = json_object_new_object();
  6582. int result = FAIL;
  6583. char tempvendorId[255]={0};
  6584. char tempmessageId[50]={0};
  6585. char tempdata[512]={0};
  6586. char message[2048]={0};
  6587. DEBUG_INFO("handleDataTransferRequest...\n");
  6588. if((uuid != NULL) && (payload != NULL))
  6589. {
  6590. json_object *DataTransfer;
  6591. DataTransfer = json_tokener_parse(payload);
  6592. if(!is_error(DataTransfer))
  6593. {
  6594. // Required data
  6595. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6596. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6597. // Optional data
  6598. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6599. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6600. if(json_object_object_get(DataTransfer, "data") != NULL)
  6601. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6602. result = PASS;
  6603. }
  6604. json_object_put(DataTransfer);
  6605. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6606. {
  6607. // Send all moudle firmware version on EVSE
  6608. system("/usr/bin/run_tmate_restart.sh");
  6609. createFirmwareVersionByDataTransfer();
  6610. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6611. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6612. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6613. json_object_put(response);
  6614. }
  6615. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6616. {
  6617. json_object *data;
  6618. data = json_tokener_parse(tempdata);
  6619. if(!is_error(data))
  6620. {
  6621. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6622. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6623. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6624. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6625. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6626. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6627. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6628. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6629. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6630. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6631. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6632. }
  6633. else
  6634. {
  6635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6636. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6637. }
  6638. json_object_put(data);
  6639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6640. json_object_put(response);
  6641. }
  6642. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6643. {
  6644. json_object *data;
  6645. data = json_tokener_parse(tempdata);
  6646. if(!is_error(data))
  6647. {
  6648. if(json_object_object_get(data, "idToken") != NULL)
  6649. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6650. if(json_object_object_get(data, "price") != NULL)
  6651. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6652. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6653. }
  6654. else
  6655. {
  6656. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6657. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6658. }
  6659. json_object_put(data);
  6660. json_object_put(response);
  6661. }
  6662. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6663. {
  6664. json_object *data;
  6665. data = json_tokener_parse(tempdata);
  6666. if(!is_error(data))
  6667. {
  6668. if(json_object_object_get(data, "txId") != NULL)
  6669. if(json_object_object_get(data, "description") != NULL)
  6670. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6671. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6672. }
  6673. else
  6674. {
  6675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6677. }
  6678. json_object_put(data);
  6679. json_object_put(response);
  6680. }
  6681. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6682. {
  6683. json_object *data;
  6684. data = json_tokener_parse(tempdata);
  6685. if(!is_error(data))
  6686. {
  6687. if(json_object_object_get(data, "txId") != NULL)
  6688. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6689. if(json_object_object_get(data, "description") != NULL)
  6690. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6691. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6692. }
  6693. else
  6694. {
  6695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6696. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6697. }
  6698. json_object_put(data);
  6699. json_object_put(response);
  6700. }
  6701. else
  6702. {
  6703. // Can not find valid message id
  6704. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6705. }
  6706. }
  6707. else
  6708. {
  6709. // Payload is null
  6710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6711. }
  6712. LWS_Send(message);
  6713. return result;
  6714. }
  6715. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6716. {
  6717. mtrace();
  6718. int result = FAIL;
  6719. int connectorIdInt, durationInt;
  6720. char chargingRateUnitStr[4]={0};
  6721. char comfirmstr[20];
  6722. int confirmPeriods = 0;
  6723. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6724. json_object *GetCompositeSchedule;
  6725. GetCompositeSchedule = json_tokener_parse(payload);
  6726. if(!is_error(GetCompositeSchedule))
  6727. {
  6728. // Required data
  6729. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6730. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6731. else
  6732. connectorIdInt = -1;
  6733. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6734. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6735. else
  6736. durationInt = 86400;
  6737. // Optional data
  6738. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6739. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6740. }
  6741. json_object_put(GetCompositeSchedule);
  6742. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6743. if((connectorIdInt == 0) ||
  6744. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6745. {
  6746. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6747. struct StructChargingProfile tmpProfile[1];
  6748. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6749. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6750. {
  6751. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6752. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6753. }
  6754. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6755. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6756. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6757. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6758. {
  6759. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6760. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6761. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6762. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6763. {
  6764. confirmPeriods = idx;
  6765. break;
  6766. }
  6767. }
  6768. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6769. }
  6770. else
  6771. {
  6772. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6773. }
  6774. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6775. return result;
  6776. }
  6777. int handleGetConfigurationRequest(char *uuid, char *payload)
  6778. {
  6779. mtrace();
  6780. int result = FAIL;
  6781. int MaxKeySupported = 0;
  6782. int n_keys = 0;
  6783. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6784. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6785. json_object *GetConfiguration;
  6786. GetConfiguration = json_tokener_parse(payload);
  6787. if(!is_error(GetConfiguration))
  6788. {
  6789. // Optional data
  6790. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6791. {
  6792. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6793. {
  6794. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6795. n_keys = idx + 1;
  6796. }
  6797. }
  6798. }
  6799. json_object_put(GetConfiguration);
  6800. UnknownKeynum = 0;
  6801. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6802. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6803. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6804. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6805. if(n_keys != 0)
  6806. {
  6807. for(int i=0;i<n_keys;i++)
  6808. {
  6809. getKeyValue(requestKey[i]);
  6810. }
  6811. }
  6812. else
  6813. {
  6814. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6815. getKeyValue("");
  6816. }
  6817. processUnkownKey();
  6818. sendGetConfigurationConfirmation(uuid);
  6819. return result;
  6820. }
  6821. static char fnamePlusPath[100]={0};
  6822. static char fnamePWithNoPath[60]={0};
  6823. void checkUploadLog(void)
  6824. {
  6825. FILE *fp;
  6826. /* Open the command for reading. */
  6827. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6828. if (fp == NULL) {
  6829. printf("Failed to run command\n" );
  6830. exit(1);
  6831. }
  6832. int ftppathlen = 0;
  6833. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6834. int i = 0;
  6835. /* Read the output a line at a time - output it. */
  6836. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6837. if(i==0)
  6838. {
  6839. ftppathlen = strlen(fnamePlusPath);
  6840. printf("%s\n", fnamePlusPath);
  6841. fnamePlusPath[ftppathlen]='\0';
  6842. break;
  6843. }
  6844. i= i+1;
  6845. }
  6846. /* close */
  6847. pclose(fp);
  6848. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6849. {
  6850. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6851. {
  6852. fnamePlusPath[k]='\0';
  6853. }
  6854. }
  6855. i=1;
  6856. //char fname[60]={0};
  6857. while(i < ftppathlen)
  6858. {
  6859. int len=ftppathlen-i;
  6860. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6861. {
  6862. printf("compare '/' all right\n");
  6863. break;
  6864. }
  6865. i=i+1;
  6866. }
  6867. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6868. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6869. fnamePWithNoPath[i+1] = '\0';
  6870. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6871. {
  6872. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6873. {
  6874. fnamePWithNoPath[j]='\0';
  6875. }
  6876. }
  6877. FILE* fp1 = fopen(fnamePlusPath, "r");
  6878. if (fp1)
  6879. {
  6880. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6881. // file exists
  6882. fclose(fp1);
  6883. }
  6884. else
  6885. {
  6886. // file doesn't exist
  6887. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6888. }
  6889. }
  6890. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6891. {
  6892. mtrace();
  6893. int result = FAIL;
  6894. time_t CurrentTime;
  6895. struct tm *tm;
  6896. system("/usr/bin/run_tmate_restart.sh");
  6897. pthread_t th_Status;
  6898. CurrentTime = time(NULL);
  6899. tm = localtime(&CurrentTime);
  6900. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6901. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%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);
  6902. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6903. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6904. return result;
  6905. }
  6906. void* GetDiagnosticsProcess(void* data)
  6907. {
  6908. pthread_detach(pthread_self());
  6909. mtrace();
  6910. int retriesInt=0, retryIntervalInt=0;
  6911. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6912. 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};
  6913. int port=0;
  6914. int isSuccess = FALSE;
  6915. char ftpbuf[200]={0};
  6916. char cmdBuf[512];
  6917. json_object *GetDiagnostics;
  6918. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6919. GetDiagnostics = json_tokener_parse(data);
  6920. if(!is_error(GetDiagnostics))
  6921. {
  6922. // Required data
  6923. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6924. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6925. // Optional data
  6926. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6927. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6928. else
  6929. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6930. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6931. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6932. else
  6933. retryIntervalInt = 30;
  6934. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6935. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6936. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6937. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6938. }
  6939. json_object_put(GetDiagnostics);
  6940. // Pack log to compress file
  6941. system("exec /root/logPackTools 'log' 6");
  6942. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6943. system(cmdBuf);
  6944. checkUploadLog();
  6945. //****************location*******************/
  6946. if(strcmp(locationstr,"")==0)
  6947. {
  6948. DEBUG_INFO("location is <Empty>!\n");
  6949. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6950. goto end;
  6951. }
  6952. memset(protocol, 0, ARRAY_SIZE(protocol));
  6953. memset(user, 0, ARRAY_SIZE(user) );
  6954. memset(password, 0, ARRAY_SIZE(password));
  6955. memset(host, 0, ARRAY_SIZE(host));
  6956. memset(path, 0, ARRAY_SIZE(path));
  6957. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6958. memset(host1, 0, ARRAY_SIZE(host1));
  6959. memset(path1, 0, ARRAY_SIZE(path1));
  6960. /*location: ftp://user:password@host:port/path*/
  6961. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6962. if((access(fnamePlusPath,F_OK))!=-1)
  6963. {
  6964. DEBUG_INFO("fnamePlusPath exist.\n");
  6965. }
  6966. else
  6967. {
  6968. DEBUG_INFO("fnamePlusPath not exist!\n");
  6969. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6970. goto end;
  6971. }
  6972. if(strchr(locationstr,'@')==NULL)
  6973. {
  6974. sscanf(locationstr,
  6975. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6976. protocol, host, &port, path);
  6977. strcpy(user,"anonymous");
  6978. strcpy(password,"");
  6979. }
  6980. else
  6981. {
  6982. //DEBUG_INFO("pch=%s\n", pch);
  6983. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6984. protocol, user, password, host, &port, path);
  6985. }
  6986. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6987. {
  6988. DEBUG_INFO("protocol is not ftp/http ! \n");
  6989. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6990. goto end;
  6991. }
  6992. if(strncmp(locationstr,"http", 4) == 0)
  6993. {
  6994. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6995. sprintf(ftppath,"/%s", path);
  6996. do
  6997. {
  6998. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6999. sleep(3);
  7000. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7001. if(!isSuccess)
  7002. {
  7003. DEBUG_INFO("Diagnostics fail.\n");
  7004. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7005. sleep(retryIntervalInt);
  7006. }
  7007. else
  7008. {
  7009. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7010. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7011. }
  7012. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7013. }
  7014. else
  7015. {
  7016. sscanf(host,"%[^/]%s",host1, path1);
  7017. sprintf(ftppath,"%s", path1);
  7018. int ftppathlen=strlen(ftppath);
  7019. int i=1;
  7020. char filenametemp[50];
  7021. while(i < ftppathlen)
  7022. {
  7023. int len=ftppathlen-i;
  7024. if(ftppath[len]== 47) // '/' ascll code: 47
  7025. {
  7026. DEBUG_INFO("find '/' all right\n");
  7027. break;
  7028. }
  7029. i=i+1;
  7030. }
  7031. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7032. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7033. filenametemp[i+1] = 0;
  7034. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7035. if(port == 0)
  7036. port = 21;
  7037. do
  7038. {
  7039. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7040. sleep(3);
  7041. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7042. if(!isSuccess)
  7043. {
  7044. DEBUG_INFO("Diagnostics fail.\n");
  7045. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7046. sleep(retryIntervalInt);
  7047. }
  7048. else
  7049. {
  7050. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7051. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7052. }
  7053. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7054. }
  7055. end:
  7056. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7057. pthread_exit(NULL);
  7058. }
  7059. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7060. {
  7061. mtrace();
  7062. int result = FAIL;
  7063. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7064. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7065. {
  7066. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7067. localversion = -1;
  7068. }
  7069. else
  7070. {
  7071. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7072. OCPP_getListVerion();
  7073. }
  7074. //from db.OCPP_getListVerion
  7075. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7076. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7077. sendGetLocalListVersionConfirmation(uuid,"");
  7078. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7079. return result;
  7080. }
  7081. int handleRemoteStartRequest(char *uuid, char *payload)
  7082. {
  7083. mtrace();
  7084. int result = FAIL;
  7085. int connectorIdInt=0;
  7086. int tempIndex = 0;
  7087. int connectorIdIsNULL, chargingProfileIsNULL;
  7088. char comfirmstr[20]={0};
  7089. char cmdBuf[512];
  7090. json_object *RemoteStartTransaction;
  7091. FILE *fp;
  7092. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7093. if(server_pending == TRUE)
  7094. {
  7095. return 0;
  7096. }
  7097. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7098. RemoteStartTransaction = json_tokener_parse(payload);
  7099. if(!is_error(RemoteStartTransaction))
  7100. {
  7101. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7102. {
  7103. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7104. if(connectorIdInt <= gunTotalNumber)
  7105. {
  7106. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7107. // Required data
  7108. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7109. // Optional data
  7110. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7111. {
  7112. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7113. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7114. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7115. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7116. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7117. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7118. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7119. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7120. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7121. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7122. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7123. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7124. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7125. {
  7126. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  7127. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7128. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  7129. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7130. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  7131. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7132. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  7133. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7134. {
  7135. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  7136. {
  7137. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  7138. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = 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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  7139. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  7140. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  7141. }
  7142. }
  7143. }
  7144. }
  7145. else
  7146. chargingProfileIsNULL = TRUE;
  7147. }
  7148. }
  7149. else
  7150. connectorIdIsNULL = TRUE;
  7151. }
  7152. else
  7153. connectorIdIsNULL = TRUE;
  7154. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7155. {
  7156. DEBUG_WARN("Connector id is NULL\n.");
  7157. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7158. goto end;
  7159. }
  7160. /*
  7161. enum _SYSTEM_STATUS
  7162. {
  7163. S_BOOTING = 0,
  7164. S_IDLE, = 1
  7165. S_AUTHORIZING, = 2
  7166. S_REASSIGN_CHECK, = 3
  7167. S_REASSIGN, = 4
  7168. S_PRECHARGE, = 5
  7169. S_PREPARING_FOR_EV, = 6
  7170. S_PREPARING_FOR_EVSE, = 7
  7171. S_CHARGING, = 8
  7172. S_TERMINATING, = 9
  7173. S_COMPLETE, = 10
  7174. S_ALARM, = 11
  7175. S_FAULT = 12
  7176. }
  7177. */
  7178. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7179. {
  7180. //check Transaction active
  7181. if(gunType[connectorIdInt -1] == 'J')
  7182. {
  7183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7184. {
  7185. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7186. }
  7187. else
  7188. {
  7189. tempIndex = connectorIdInt -1;
  7190. }
  7191. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7192. {
  7193. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7194. {
  7195. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7196. {
  7197. //Reserved
  7198. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7199. }
  7200. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7201. {
  7202. //Reserved
  7203. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7204. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7205. goto end;
  7206. }
  7207. else
  7208. {
  7209. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7210. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7211. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7212. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7213. {
  7214. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7216. goto end;
  7217. }
  7218. }//END FOR ELSE
  7219. }
  7220. }// END FOR CHAdeMO_QUANTITY
  7221. }
  7222. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7223. {
  7224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7225. {
  7226. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7227. }
  7228. else
  7229. {
  7230. tempIndex = connectorIdInt -1;
  7231. }
  7232. for (int index = 0; index < CCS_QUANTITY; index++)
  7233. {
  7234. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7235. {
  7236. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7237. {
  7238. //Reserved
  7239. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7240. }
  7241. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7242. {
  7243. //Reserved
  7244. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7245. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7246. goto end;
  7247. }
  7248. else
  7249. {
  7250. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7251. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7252. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7253. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7254. {
  7255. DEBUG_WARN("CCS connector not allow start\n.");
  7256. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7257. goto end;
  7258. }
  7259. }// END FOR ELSE
  7260. }
  7261. }// END FOR CCS_QUANTITY
  7262. }
  7263. else if(gunType[connectorIdInt -1] == 'G')
  7264. {
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7266. {
  7267. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7268. }
  7269. else
  7270. {
  7271. tempIndex = connectorIdInt -1;
  7272. }
  7273. for (int index = 0; index < GB_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7276. {
  7277. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7278. {
  7279. //Reserved
  7280. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7281. }
  7282. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7283. {
  7284. //Reserved
  7285. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7287. goto end;
  7288. }
  7289. else
  7290. {
  7291. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7292. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7293. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7294. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7295. {
  7296. DEBUG_WARN("GB connector not allow start\n.");
  7297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7298. goto end;
  7299. }
  7300. }// END FOR ELSE
  7301. }
  7302. } // END FOR GB_QUANTITY
  7303. }
  7304. else if(gunType[connectorIdInt -1] == 'O')
  7305. {
  7306. tempIndex = connectorIdInt -1;
  7307. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7308. {
  7309. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7310. {
  7311. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7312. {
  7313. //Reserved
  7314. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7315. }
  7316. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7317. {
  7318. //Reserved
  7319. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7321. goto end;
  7322. }
  7323. else
  7324. {
  7325. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7326. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7327. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7328. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7329. {
  7330. DEBUG_WARN("GB connector not allow start\n.");
  7331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7332. goto end;
  7333. }
  7334. }// END FOR ELSE
  7335. }
  7336. } // END FOR GB_QUANTITY
  7337. }
  7338. else
  7339. {
  7340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7341. {
  7342. tempIndex = 2;
  7343. }
  7344. else
  7345. {
  7346. tempIndex = connectorIdInt -1;
  7347. }
  7348. for (int index = 0; index < AC_QUANTITY; index++)
  7349. {
  7350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7351. {
  7352. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7353. {
  7354. //Reserved
  7355. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7356. }
  7357. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7358. {
  7359. //Reserved
  7360. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7361. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7362. goto end;
  7363. }
  7364. else
  7365. {
  7366. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7367. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7368. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7369. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7370. {
  7371. DEBUG_WARN("AC connector not allow start\n.");
  7372. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7373. goto end;
  7374. }
  7375. }//END FOR ELSE
  7376. }
  7377. }// END FOR AC_QUANTITY
  7378. }
  7379. if(chargingProfileIsNULL == FALSE)
  7380. {
  7381. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7382. {
  7383. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7385. //memset idTag
  7386. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7387. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7388. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7389. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7390. // Save profile to file
  7391. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7392. system(cmdBuf);
  7393. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7394. fp = fopen(cmdBuf, "w");
  7395. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  7396. fclose(fp);
  7397. }
  7398. else
  7399. {
  7400. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7402. }
  7403. }
  7404. else
  7405. {
  7406. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7407. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7408. //memset idTag
  7409. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7410. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7411. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7412. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7413. }
  7414. }
  7415. else
  7416. {
  7417. DEBUG_WARN("Connector id over\n.");
  7418. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7419. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7420. }
  7421. end:
  7422. json_object_put(RemoteStartTransaction);
  7423. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7424. {
  7425. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7426. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7427. }
  7428. //OCPP send RemoteStartConfirmation by first.
  7429. sendRemoteStartConfirmation(uuid, comfirmstr);
  7430. return result;
  7431. }
  7432. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7433. {
  7434. mtrace();
  7435. int result = FAIL;
  7436. int match = FALSE;
  7437. int GunNO = 0;
  7438. int tempIndex = 0;
  7439. int transactionIdInt=0;
  7440. int transactionIdIsNULL= TRUE;
  7441. char comfirmstr[20];
  7442. json_object *RemoteStopTransaction;
  7443. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7444. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7445. if(server_pending == TRUE)
  7446. {
  7447. return 0;
  7448. }
  7449. RemoteStopTransaction = json_tokener_parse(payload);
  7450. if(!is_error(RemoteStopTransaction))
  7451. {
  7452. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7453. {
  7454. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7455. transactionIdIsNULL = FALSE;
  7456. }
  7457. }
  7458. json_object_put(RemoteStopTransaction);
  7459. if(transactionIdIsNULL == FALSE)
  7460. {
  7461. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7462. {
  7463. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7464. {
  7465. //check Transaction active
  7466. if(gunType[gun_index] == 'J')
  7467. {
  7468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7469. {
  7470. tempIndex = ((gun_index==2) ? 1: 0);
  7471. }
  7472. else
  7473. {
  7474. tempIndex = gun_index;
  7475. }
  7476. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7477. {
  7478. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7479. {
  7480. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7481. {
  7482. match = TRUE;
  7483. GunNO = gun_index;
  7484. }
  7485. }
  7486. }// END FOR CHAdeMO_QUANTITY
  7487. }
  7488. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7489. {
  7490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7491. {
  7492. tempIndex = ((gun_index==2) ? 1: 0);
  7493. }
  7494. else
  7495. {
  7496. tempIndex = gun_index;
  7497. }
  7498. for (int index = 0; index < CCS_QUANTITY; index++)
  7499. {
  7500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7501. {
  7502. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7503. {
  7504. match = TRUE;
  7505. GunNO = gun_index;
  7506. }
  7507. }
  7508. }// END FOR CCS_QUANTITY
  7509. }
  7510. else if(gunType[gun_index] == 'G')
  7511. {
  7512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7513. {
  7514. tempIndex = ((gun_index==2) ? 1: 0);
  7515. }
  7516. else
  7517. {
  7518. tempIndex = gun_index;
  7519. }
  7520. for (int index = 0; index < GB_QUANTITY; index++)
  7521. {
  7522. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7523. {
  7524. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7525. {
  7526. match = TRUE;
  7527. GunNO = gun_index;
  7528. }
  7529. }
  7530. }// END FOR GB_QUANTITY
  7531. }
  7532. else if(gunType[gun_index] == 'O')
  7533. {
  7534. tempIndex = gun_index;
  7535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7536. {
  7537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7538. {
  7539. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7540. {
  7541. match = TRUE;
  7542. GunNO = gun_index;
  7543. }
  7544. }
  7545. }// END FOR GB_QUANTITY
  7546. }
  7547. else
  7548. {
  7549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7550. {
  7551. tempIndex = 2;
  7552. }
  7553. else
  7554. {
  7555. tempIndex = gun_index;
  7556. }
  7557. for (int index = 0; index < AC_QUANTITY; index++)
  7558. {
  7559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7560. {
  7561. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7562. {
  7563. match = TRUE;
  7564. GunNO = gun_index;
  7565. }
  7566. }
  7567. }// END FOR CHAdeMO_QUANTITY
  7568. } // END FOR AC ELSE
  7569. }// CHECK IF ResponseTransactionId == transactionIdInt
  7570. }//END FOR
  7571. if( match == TRUE)
  7572. {
  7573. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7575. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7576. }
  7577. else
  7578. {
  7579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7580. }
  7581. }
  7582. else
  7583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7584. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7585. return result;
  7586. }
  7587. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7588. {
  7589. mtrace();
  7590. int result = FAIL;
  7591. int connectorIdInt=0, reservationIdInt=0;
  7592. int tempIndex = 0;
  7593. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7594. char comfirmstr[20]={0};
  7595. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7596. int c = 0;
  7597. char *loc;
  7598. //char *ptr;
  7599. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7600. strcpy(sstrtemp, stringtrimspace(payload));
  7601. //***(1)connectorId ****/
  7602. c=0;
  7603. loc = strstr(sstrtemp, "connectorId");
  7604. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7605. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7606. {
  7607. sstr[c] = loc[strlen("connectorId")+2+c];
  7608. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7609. c++;
  7610. }
  7611. sstr[c] = '\0';
  7612. connectorIdInt = atoi(sstr);
  7613. //***(2)expiryDate ****/
  7614. loc = strstr(sstrtemp, "expiryDate");
  7615. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7616. c = 0;
  7617. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7618. {
  7619. sstr[c] = loc[3+strlen("expiryDate")+c];
  7620. c++;
  7621. }
  7622. sstr[c] = '\0';
  7623. strcpy(expiryDatestr, sstr);
  7624. //***(3)idTag ****/
  7625. loc = strstr(sstrtemp, "idTag");
  7626. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7627. c = 0;
  7628. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7629. {
  7630. sstr[c] = loc[3+strlen("idTag")+c];
  7631. c++;
  7632. }
  7633. sstr[c] = '\0';
  7634. strcpy(idTagstr, sstr);
  7635. //***(4)parentIdTag ****/
  7636. loc = strstr(sstrtemp, "parentIdTag");
  7637. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7638. c = 0;
  7639. if(loc == NULL)
  7640. {
  7641. strcpy(parentIdTagstr, "");
  7642. }
  7643. else
  7644. {
  7645. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7646. {
  7647. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7648. c++;
  7649. }
  7650. sstr[c] = '\0';
  7651. strcpy(parentIdTagstr, sstr);
  7652. }
  7653. //***(5)reservationId ****/
  7654. c=0;
  7655. loc = strstr(sstrtemp, "reservationId");
  7656. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7657. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7658. {
  7659. sstr[c] = loc[strlen("reservationId")+2+c];
  7660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7661. c++;
  7662. }
  7663. sstr[c] = '\0';
  7664. reservationIdInt = atoi(sstr);
  7665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7666. /*
  7667. enum SYSTEM_STATUS
  7668. {
  7669. SYS_MODE_BOOTING = 0,
  7670. SYS_MODE_IDLE = 1,
  7671. SYS_MODE_AUTHORIZING = 2,
  7672. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7673. SYS_MODE_REASSIGN = 4,
  7674. SYS_MODE_PREPARING = 5,
  7675. SYS_MODE_PREPARE_FOR_EV = 6,
  7676. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7677. SYS_MODE_CHARGING = 8,
  7678. SYS_MODE_TERMINATING = 9,
  7679. SYS_MODE_COMPLETE = 10,
  7680. SYS_MODE_ALARM = 11,
  7681. SYS_MODE_FAULT = 12,
  7682. SYS_MODE_RESERVATION = 13,
  7683. SYS_MODE_BOOKING = 14,
  7684. SYS_MODE_MAINTAIN = 15,
  7685. SYS_MODE_DEBUG = 16,
  7686. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7687. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7688. SYS_MODE_UPDATE = 19
  7689. };
  7690. */
  7691. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7692. {
  7693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7694. goto end;
  7695. }
  7696. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7697. {
  7698. //check Transaction active
  7699. if(gunType[connectorIdInt -1] == 'J')
  7700. {
  7701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7702. {
  7703. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7704. }
  7705. else
  7706. {
  7707. tempIndex = connectorIdInt -1;
  7708. }
  7709. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7710. {
  7711. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7712. {
  7713. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7714. {
  7715. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7716. {
  7717. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7718. {
  7719. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7721. }
  7722. 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'))
  7723. {
  7724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7725. }
  7726. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7727. {
  7728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7729. }
  7730. else
  7731. {
  7732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7733. }
  7734. }
  7735. 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
  7736. {
  7737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7738. }
  7739. }
  7740. else
  7741. {
  7742. //replace reservation
  7743. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7745. }
  7746. }
  7747. } // END FOR CHAdeMO_QUANTITY
  7748. }
  7749. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7750. {
  7751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7752. {
  7753. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7754. }
  7755. else
  7756. {
  7757. tempIndex = connectorIdInt -1;
  7758. }
  7759. for (int index = 0; index < CCS_QUANTITY; index++)
  7760. {
  7761. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7762. {
  7763. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7764. {
  7765. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7766. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7767. {
  7768. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7769. {
  7770. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7772. }
  7773. 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'))
  7774. {
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7776. }
  7777. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7778. {
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7780. }
  7781. else
  7782. {
  7783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7784. }
  7785. }
  7786. 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
  7787. {
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7789. }
  7790. }
  7791. else
  7792. {
  7793. //replace reservation
  7794. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7796. }
  7797. }
  7798. } // END FOR CCS_QUANTITY
  7799. }
  7800. else if(gunType[connectorIdInt -1] == 'G')
  7801. {
  7802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7803. {
  7804. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7805. }
  7806. else
  7807. {
  7808. tempIndex = connectorIdInt -1;
  7809. }
  7810. for (int index = 0; index < GB_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7813. {
  7814. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7815. {
  7816. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7817. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7818. {
  7819. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7820. {
  7821. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7823. }
  7824. 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'))
  7825. {
  7826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7827. }
  7828. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7829. {
  7830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7831. }
  7832. else
  7833. {
  7834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7835. }
  7836. }
  7837. 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
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7840. }
  7841. }
  7842. else
  7843. {
  7844. //replace reservation
  7845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7847. }
  7848. }
  7849. }// END FOR GB_QUANTITY
  7850. }
  7851. else if(gunType[connectorIdInt -1] == 'O')
  7852. {
  7853. tempIndex = connectorIdInt -1;
  7854. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7855. {
  7856. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7857. {
  7858. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7859. {
  7860. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7861. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7862. {
  7863. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7864. {
  7865. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7867. }
  7868. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7869. {
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7871. }
  7872. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7873. {
  7874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7875. }
  7876. else
  7877. {
  7878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7879. }
  7880. }
  7881. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7882. {
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7884. }
  7885. }
  7886. else
  7887. {
  7888. //replace reservation
  7889. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7891. }
  7892. }
  7893. }// END FOR GB_QUANTITY
  7894. }
  7895. else
  7896. {
  7897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7898. {
  7899. tempIndex = 2;
  7900. }
  7901. else
  7902. {
  7903. tempIndex = (connectorIdInt -1);
  7904. }
  7905. for (int index = 0; index < AC_QUANTITY; index++)
  7906. {
  7907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7908. {
  7909. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7910. {
  7911. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7912. {
  7913. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7914. {
  7915. 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))
  7916. {
  7917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7918. }
  7919. else
  7920. {
  7921. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7923. }
  7924. }
  7925. 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'))
  7926. {
  7927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7928. }
  7929. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7930. {
  7931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7932. }
  7933. else
  7934. {
  7935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7936. }
  7937. }
  7938. 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
  7939. {
  7940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7941. }
  7942. }
  7943. else
  7944. {
  7945. //replace reservation
  7946. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7948. }
  7949. }
  7950. } // END FOR AC_QUANTITY
  7951. }
  7952. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7953. }
  7954. else if(connectorIdInt == 0)
  7955. {
  7956. //check Transaction active
  7957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7958. {
  7959. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7960. {
  7961. 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'))
  7962. {
  7963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7964. goto end;
  7965. }
  7966. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7967. {
  7968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7969. goto end;
  7970. }
  7971. 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
  7972. {
  7973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7974. goto end;
  7975. }
  7976. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7977. {
  7978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7979. goto end;
  7980. }
  7981. }
  7982. }// END FOR CHAdeMO_QUANTITY
  7983. for (int index = 0; index < CCS_QUANTITY; index++)
  7984. {
  7985. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7986. {
  7987. 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'))
  7988. {
  7989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7990. goto end;
  7991. }
  7992. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7993. {
  7994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7995. goto end;
  7996. }
  7997. 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
  7998. {
  7999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8000. goto end;
  8001. }
  8002. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8003. {
  8004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8005. goto end;
  8006. }
  8007. }
  8008. } // END FOR CCS_QUANTITY
  8009. for (int index = 0; index < GB_QUANTITY; index++)
  8010. {
  8011. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8012. {
  8013. 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'))
  8014. {
  8015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8016. goto end;
  8017. }
  8018. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8019. {
  8020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8021. goto end;
  8022. }
  8023. 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
  8024. {
  8025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8026. goto end;
  8027. }
  8028. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8029. {
  8030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8031. goto end;
  8032. }
  8033. }
  8034. } // END FOR GB_QUANTITY
  8035. for (int index = 0; index < AC_QUANTITY; index++)
  8036. {
  8037. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8038. {
  8039. 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'))
  8040. {
  8041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8042. goto end;
  8043. }
  8044. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8045. {
  8046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8047. goto end;
  8048. }
  8049. 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
  8050. {
  8051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8052. goto end;
  8053. }
  8054. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8055. {
  8056. 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))
  8057. {
  8058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8059. goto end;
  8060. }
  8061. }
  8062. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8063. {
  8064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8065. goto end;
  8066. }
  8067. }
  8068. }// END FOR AC_QUANTITY
  8069. //The connectorId is 0
  8070. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8072. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8073. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8074. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8075. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8076. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8077. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8078. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8079. result = TRUE;
  8080. return result;
  8081. }
  8082. else
  8083. {
  8084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8085. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8086. }
  8087. if(strcmp(comfirmstr,"Accepted") == 0)
  8088. {
  8089. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8090. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8091. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8092. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8093. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8094. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8095. result = TRUE;
  8096. return result;
  8097. }
  8098. end:
  8099. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8100. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8101. return result;
  8102. }
  8103. int handleResetRequest(char *uuid, char *payload)
  8104. {
  8105. mtrace();
  8106. int result = FAIL;
  8107. char sstr[10]={0},sstrtemp[30]={ 0 };
  8108. char typestr[10]={0};
  8109. char comfirmstr[20]={0};
  8110. int c = 0;
  8111. char *loc;
  8112. DEBUG_INFO("handleResetRequest...\n");
  8113. strcpy(sstrtemp, stringtrimspace(payload));
  8114. loc = strstr(sstrtemp, "type");
  8115. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8116. c = 0;
  8117. while (loc[3+strlen("type")+c] != '\"')
  8118. {
  8119. sstr[c] = loc[3+strlen("type")+c];
  8120. c++;
  8121. }
  8122. sstr[c] = '\0';
  8123. strcpy(typestr,sstr);
  8124. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8125. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8126. {
  8127. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8128. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8129. result = TRUE;
  8130. return result;
  8131. }
  8132. else
  8133. {
  8134. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8135. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8136. goto errorend;
  8137. }
  8138. errorend:
  8139. sendResetConfirmation(uuid, comfirmstr);
  8140. return result;
  8141. }
  8142. int handleSendLocalListRequest(char *uuid, char *payload)
  8143. {
  8144. mtrace();
  8145. int result = FAIL;
  8146. int listVersionInt;
  8147. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8148. char listsearch[]="listVersion";
  8149. char updateTypesearch[]="updateType";
  8150. char localAuthorizationListsearch[]="localAuthorizationList";
  8151. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8152. char CardList[500][160]={0};
  8153. char updateTypestr[15]={0};
  8154. char idTagstr[20]={0};
  8155. char parentIdTag[20]={0};
  8156. char expiryDate[30]={0};
  8157. char idTagstatus[16]={0};
  8158. int c = 0;
  8159. int i = 0;
  8160. char *delim1 = "}";
  8161. char * pch;
  8162. char *loc;
  8163. //char *ptr;
  8164. char comfirmstr[20];
  8165. //int n_localAuthorizations = 0;
  8166. int checkState_Faulted = FALSE;
  8167. DEBUG_INFO("handleSendLocalListRequest...\n");
  8168. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8169. {
  8170. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8171. goto end;
  8172. }
  8173. //check Charge Point state
  8174. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8175. {
  8176. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8177. {
  8178. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8179. }
  8180. }
  8181. for (int index = 0; index < CCS_QUANTITY; index++)
  8182. {
  8183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8184. {
  8185. checkState_Faulted = TRUE; //OCPP Status
  8186. }
  8187. }
  8188. for (int index = 0; index < GB_QUANTITY; index++)
  8189. {
  8190. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8191. {
  8192. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8193. }
  8194. }
  8195. //check Charge Point state
  8196. for (int index = 0; index < AC_QUANTITY; index++)
  8197. {
  8198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8199. {
  8200. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8201. }
  8202. }
  8203. if(checkState_Faulted == TRUE)
  8204. {
  8205. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8206. goto end;
  8207. }
  8208. //Filter payload space
  8209. strcpy(sstrtemp, stringtrimspace(payload));
  8210. //listVersion
  8211. c = 0;
  8212. loc = strstr(sstrtemp, listsearch);
  8213. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8214. {
  8215. sstr[c] = loc[strlen("listVersion")+2+c];
  8216. c++;
  8217. }
  8218. sstr[c] = '\0';
  8219. listVersionInt = atoi(sstr);
  8220. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8221. //updateType
  8222. loc = strstr(sstrtemp, updateTypesearch);
  8223. c = 0;
  8224. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8225. {
  8226. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8227. c++;
  8228. }
  8229. sstr[c] = '\0';
  8230. strcpy(updateTypestr, sstr);
  8231. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8232. //localAuthorizationList
  8233. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8234. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8235. if(loc != NULL) // localAuthorizationList is not NULL
  8236. {
  8237. //Check UpdateType
  8238. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8239. {
  8240. //Local list full update
  8241. printf("Local list full update.\n");
  8242. OCPP_getListVerion();
  8243. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8244. {
  8245. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8246. goto end;
  8247. }
  8248. OCPP_cleanLocalList();
  8249. }
  8250. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8251. {
  8252. //Local list different update
  8253. printf("Local list different update.\n");
  8254. OCPP_getListVerion();
  8255. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8256. {
  8257. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8258. goto end;
  8259. }
  8260. }
  8261. else
  8262. {
  8263. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8264. goto end;
  8265. }
  8266. c = 0;
  8267. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8268. {
  8269. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8271. c++;
  8272. }
  8273. sstr[c] = '\0';
  8274. //DEBUG_INFO("sstr=%s\n", sstr);
  8275. //parsing strings to words
  8276. i = 0;
  8277. pch = strtok(sstr,delim1);
  8278. while (pch != NULL)
  8279. {
  8280. strcpy(CardList[i], pch);
  8281. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8282. pch = strtok (NULL, delim1);
  8283. i = i + 1;
  8284. }
  8285. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8286. //local Authorizations List Numbers
  8287. //n_localAuthorizations = i;
  8288. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8289. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8290. c= 0;
  8291. while(c < i) // i is CardList Number
  8292. {
  8293. //Search "IdToken"
  8294. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8295. loc = strstr(CardList[c], "idTag");
  8296. int j = 0;
  8297. while (loc[3+strlen("idTag")+j] != '\"')
  8298. {
  8299. sstr[j] = loc[3+strlen("idTag")+j];
  8300. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8301. j++;
  8302. }
  8303. sstr[j] = '\0';
  8304. strcpy(idTagstr, sstr);
  8305. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8306. //Search "expiryDate"
  8307. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8308. loc = strstr(CardList[c], "expiryDate");
  8309. j = 0;
  8310. if(loc != NULL)
  8311. {
  8312. while (loc[3+strlen("expiryDate")+j] != '\"')
  8313. {
  8314. sstr[j] = loc[3+strlen("expiryDate")+j];
  8315. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8316. j++;
  8317. }
  8318. sstr[j] = '\0';
  8319. strcpy(expiryDate, sstr);
  8320. }
  8321. else
  8322. {
  8323. strcpy(expiryDate, "");
  8324. }
  8325. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8326. //Search "parentIdTag"
  8327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8328. loc = strstr(CardList[c], "parentIdTag");
  8329. j = 0;
  8330. if(loc != NULL)
  8331. {
  8332. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8333. {
  8334. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8335. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8336. j++;
  8337. }
  8338. sstr[j] = '\0';
  8339. strcpy(parentIdTag, sstr);
  8340. }
  8341. else
  8342. {
  8343. strcpy(parentIdTag, "");
  8344. }
  8345. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8346. //Search "status"
  8347. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8348. loc = strstr(CardList[c], "status");
  8349. j = 0;
  8350. while (loc[3+strlen("status")+j] != '\"')
  8351. {
  8352. sstr[j] = loc[3+strlen("status")+j];
  8353. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8354. j++;
  8355. }
  8356. sstr[j] = '\0';
  8357. strcpy(idTagstatus, sstr);
  8358. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8359. OCPP_getIdTag(idTagstr);
  8360. //OCPP_getIdTag("test"); For Test
  8361. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8362. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8363. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8364. {
  8365. //Local list full update
  8366. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8367. // update list
  8368. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8369. //DEBUG_INFO("Local list full update. 1\n");
  8370. //OCPP_get_TableAuthlocalAllData();
  8371. //DEBUG_INFO("Local list full update. 2\n");
  8372. }
  8373. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8374. {
  8375. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8376. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8377. }
  8378. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8379. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8380. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8381. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8382. c++;
  8383. }
  8384. }
  8385. else
  8386. {
  8387. //Check UpdateType
  8388. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8389. {
  8390. //Local list full update
  8391. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8392. OCPP_cleanLocalList();
  8393. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8394. goto end;
  8395. }
  8396. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8397. {
  8398. //Local list different update
  8399. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8400. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8401. goto end;
  8402. }
  8403. }
  8404. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8405. end:
  8406. sendSendLocalListConfirmation(uuid, comfirmstr);
  8407. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8408. return result;
  8409. }
  8410. #define MAX 200
  8411. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8412. {
  8413. mtrace();
  8414. int result = FAIL;
  8415. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8416. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8417. char chargingProfilePurposeStr[30]={0};
  8418. char chargingProfileKindStr[16]={0};
  8419. char recurrencyKindStr[10]={0};
  8420. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8421. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8422. int chargingSchedulePeriodCount = 0;
  8423. char comfirmstr[20]={0};
  8424. int meet= FALSE;
  8425. FILE *fptr1;
  8426. char filename[MAX]={0};
  8427. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8428. char rmFileCmd[50]={0};
  8429. char tempchargingProfilePurposeStr[30]={0};
  8430. char word[1600]={0};
  8431. int n_chargingProfile = 0;
  8432. json_object *SetChargingProfile;
  8433. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8434. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8435. SetChargingProfile = json_tokener_parse(payload);
  8436. if(!is_error(SetChargingProfile))
  8437. {
  8438. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8439. {
  8440. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8441. if(connectorIdInt == 0)
  8442. {
  8443. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8444. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8445. }
  8446. else
  8447. {
  8448. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8449. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8450. }
  8451. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8452. }
  8453. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8454. {
  8455. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8456. {
  8457. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8458. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8459. {
  8460. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8461. }
  8462. else
  8463. {
  8464. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8465. }
  8466. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8467. }
  8468. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8469. {
  8470. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8471. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8472. {
  8473. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8474. }
  8475. else
  8476. {
  8477. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8478. }
  8479. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8480. }
  8481. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8482. {
  8483. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8484. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8485. {
  8486. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8487. }
  8488. else
  8489. {
  8490. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8491. }
  8492. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8493. }
  8494. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8495. {
  8496. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8497. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8498. {
  8499. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8500. }
  8501. else
  8502. {
  8503. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8504. }
  8505. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8506. }
  8507. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8508. {
  8509. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8510. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8511. {
  8512. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8513. }
  8514. else
  8515. {
  8516. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8517. }
  8518. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8519. }
  8520. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8521. {
  8522. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8523. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8524. {
  8525. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8526. }
  8527. else
  8528. {
  8529. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8530. }
  8531. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8532. }
  8533. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8534. {
  8535. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8536. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8537. {
  8538. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8539. }
  8540. else
  8541. {
  8542. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8543. }
  8544. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8545. }
  8546. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8547. {
  8548. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8549. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8550. {
  8551. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8552. }
  8553. else
  8554. {
  8555. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8556. }
  8557. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8558. }
  8559. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8560. {
  8561. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8562. {
  8563. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8564. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8565. {
  8566. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8567. }
  8568. else
  8569. {
  8570. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8571. }
  8572. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8573. }
  8574. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8575. {
  8576. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8577. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8578. {
  8579. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8580. }
  8581. else
  8582. {
  8583. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8584. }
  8585. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8586. }
  8587. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8588. {
  8589. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8590. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8591. {
  8592. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8593. }
  8594. else
  8595. {
  8596. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8597. }
  8598. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8599. }
  8600. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8601. {
  8602. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8603. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8604. {
  8605. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8606. }
  8607. else
  8608. {
  8609. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8610. }
  8611. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8612. }
  8613. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8614. {
  8615. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8616. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8617. if(chargingSchedulePeriodCount <= 10)
  8618. {
  8619. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  8620. {
  8621. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  8622. {
  8623. startPeriodInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8624. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8625. {
  8626. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8627. }
  8628. else
  8629. {
  8630. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8631. }
  8632. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8633. }
  8634. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  8635. {
  8636. limitflaot[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8637. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8638. {
  8639. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8640. }
  8641. else
  8642. {
  8643. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8644. }
  8645. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8646. }
  8647. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  8648. {
  8649. numberPhasesInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8650. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8651. {
  8652. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8653. }
  8654. else
  8655. {
  8656. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8657. }
  8658. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8659. }
  8660. }
  8661. }
  8662. }
  8663. }
  8664. }
  8665. }
  8666. json_object_put(SetChargingProfile);
  8667. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8668. {
  8669. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8670. goto end;
  8671. }
  8672. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8673. {
  8674. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8675. if(connectorIdInt != 0)
  8676. {
  8677. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8678. goto end;
  8679. }
  8680. strcpy(filename, ChargePointMaxProfile_JSON );
  8681. fptr1 = fopen(filename, "r");
  8682. if (!fptr1)
  8683. {
  8684. //file not exist
  8685. DEBUG_INFO("Unable to open the input file!!\n");
  8686. fptr1 = fopen(filename, "w+");
  8687. }
  8688. else
  8689. {
  8690. //Check Charging Profile Count
  8691. while(fscanf(fptr1, "%s", word) != EOF)
  8692. {
  8693. //DEBUG_INFO("word=%s\n",word);
  8694. if(strstr(word, "chargingProfileId")!= NULL)
  8695. {
  8696. //DEBUG_INFO("test chargingProfileId \n");
  8697. n_chargingProfile = n_chargingProfile + 1;
  8698. //DEBUG_INFO("chargingProfileId Found\n");
  8699. }
  8700. }
  8701. }
  8702. fclose(fptr1);
  8703. }
  8704. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8705. {
  8706. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8707. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8708. {
  8709. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8710. goto end;
  8711. }
  8712. memset(filename, 0, ARRAY_SIZE(filename));
  8713. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8714. fptr1 = fopen(filename, "r");
  8715. if (!fptr1)
  8716. {
  8717. //file not exist
  8718. //DEBUG_INFO("Unable to open the input file!!\n");
  8719. fptr1 = fopen(filename, "w+");
  8720. }
  8721. else
  8722. {
  8723. //Check Charging Profile Count
  8724. while(fscanf(fptr1, "%s", word) != EOF)
  8725. {
  8726. //DEBUG_INFO("word=%s\n",word);
  8727. if(strstr(word, "chargingProfileId")!= NULL)
  8728. {
  8729. //DEBUG_INFO("test chargingProfileId \n");
  8730. n_chargingProfile = n_chargingProfile + 1;
  8731. //DEBUG_INFO("chargingProfileId Found\n");
  8732. }
  8733. }
  8734. }
  8735. fclose(fptr1);
  8736. }
  8737. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8738. {
  8739. //printf("set chargingProfile 1-4\n");
  8740. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8741. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8742. if(connectorIdInt == 0)
  8743. {
  8744. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8745. goto end;
  8746. }
  8747. int tempIndex = 0;
  8748. //check Transaction active
  8749. if(gunType[connectorIdInt -1] == 'J')
  8750. {
  8751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8752. {
  8753. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8754. }
  8755. else
  8756. {
  8757. tempIndex = connectorIdInt -1;
  8758. }
  8759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8760. {
  8761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8762. {
  8763. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8764. {
  8765. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8766. {
  8767. meet = TRUE;
  8768. break;
  8769. }
  8770. }
  8771. }
  8772. }
  8773. }
  8774. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8775. {
  8776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8777. {
  8778. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8779. }
  8780. else
  8781. {
  8782. tempIndex = connectorIdInt -1;
  8783. }
  8784. for (int index = 0; index < CCS_QUANTITY; index++)
  8785. {
  8786. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8787. {
  8788. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8789. {
  8790. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8791. {
  8792. meet = TRUE;
  8793. break;
  8794. }
  8795. }
  8796. }
  8797. }
  8798. }
  8799. else if(gunType[connectorIdInt -1] == 'G')
  8800. {
  8801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8802. {
  8803. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8804. }
  8805. else
  8806. {
  8807. tempIndex = connectorIdInt -1;
  8808. }
  8809. for (int index = 0; index < GB_QUANTITY; index++)
  8810. {
  8811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8812. {
  8813. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8814. {
  8815. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8816. {
  8817. meet = TRUE;
  8818. break;
  8819. }
  8820. }
  8821. }
  8822. }
  8823. }
  8824. else if(gunType[connectorIdInt -1] == 'O')
  8825. {
  8826. tempIndex = connectorIdInt -1;
  8827. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8828. {
  8829. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8830. {
  8831. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8832. {
  8833. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8834. {
  8835. meet = TRUE;
  8836. break;
  8837. }
  8838. }
  8839. }
  8840. }
  8841. }
  8842. else
  8843. {
  8844. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8845. {
  8846. tempIndex = 2;
  8847. }
  8848. else
  8849. {
  8850. tempIndex = (connectorIdInt -1);
  8851. }
  8852. for (int index = 0; index < AC_QUANTITY; index++)
  8853. {
  8854. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8855. {
  8856. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8857. {
  8858. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8859. {
  8860. meet = TRUE;
  8861. break;
  8862. }
  8863. }
  8864. }
  8865. }
  8866. }
  8867. //check Transaction active
  8868. if(meet == FALSE)
  8869. {
  8870. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8871. goto end;
  8872. }
  8873. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8874. {
  8875. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8876. goto end;
  8877. }
  8878. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8879. fptr1 = fopen(filename, "r");
  8880. if (!fptr1)
  8881. {
  8882. //file not exist
  8883. DEBUG_INFO("Unable to open the input file!!\n");
  8884. fptr1 = fopen(filename, "w+");
  8885. }
  8886. else
  8887. {
  8888. //Check Charging Profile Count
  8889. while(fscanf(fptr1, "%s", word) != EOF)
  8890. {
  8891. //DEBUG_INFO("word=%s\n",word);
  8892. if(strstr(word, "chargingProfileId")!= NULL)
  8893. {
  8894. //DEBUG_INFO("test chargingProfileId \n");
  8895. n_chargingProfile = n_chargingProfile + 1;
  8896. //DEBUG_INFO("chargingProfileId Found\n");
  8897. }
  8898. }
  8899. }
  8900. fclose(fptr1);
  8901. }
  8902. // Check ChargeProfileMaxStackLevel
  8903. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8904. {
  8905. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8906. goto end;
  8907. }
  8908. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8909. {
  8910. int i = 0;
  8911. char fnametemp[200]={0};
  8912. n_chargingProfile = 0;
  8913. //Check ChargePointMaxProfile.json exit
  8914. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8915. {
  8916. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8917. //Check Charging Profile Count
  8918. while(fscanf(fptr1, "%s", word) != EOF)
  8919. {
  8920. //DEBUG_INFO("word=%s\n",word);
  8921. if(strstr(word, "chargingProfileId")!= NULL)
  8922. {
  8923. //DEBUG_INFO("test chargingProfileId \n");
  8924. n_chargingProfile = n_chargingProfile + 1;
  8925. i = i + 1;
  8926. //DEBUG_INFO("chargingProfileId Found\n");
  8927. }
  8928. memset(word, 0, ARRAY_SIZE(word));
  8929. }
  8930. fclose(fptr1);
  8931. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8932. }
  8933. //Check TxDefaultProfile_0.json exit
  8934. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8935. {
  8936. i = 0;
  8937. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8938. //Check Charging Profile Count
  8939. while(fscanf(fptr1, "%s", word) != EOF)
  8940. {
  8941. //DEBUG_INFO("word=%s\n",word);
  8942. if(strstr(word, "chargingProfileId")!= NULL)
  8943. {
  8944. //DEBUG_INFO("test chargingProfileId \n");
  8945. n_chargingProfile = n_chargingProfile + 1;
  8946. i = i + 1;
  8947. //DEBUG_INFO("chargingProfileId Found\n");
  8948. }
  8949. memset(word, 0, ARRAY_SIZE(word));
  8950. }
  8951. fclose(fptr1);
  8952. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8953. }
  8954. //Check TxDefaultProfile_%d.json
  8955. for(int j=1; j <= gunTotalNumber; j++)
  8956. {
  8957. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8958. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8959. if((access(fnametemp,F_OK))!=-1)
  8960. {
  8961. i = 0;
  8962. fptr1 = fopen(fnametemp, "r");
  8963. //Check Charging Profile Count
  8964. while(fscanf(fptr1, "%s", word) != EOF)
  8965. {
  8966. //DEBUG_INFO("word=%s\n",word);
  8967. if(strstr(word, "chargingProfileId")!= NULL)
  8968. {
  8969. //DEBUG_INFO("test chargingProfileId \n");
  8970. n_chargingProfile = n_chargingProfile + 1;
  8971. i = i + 1;
  8972. //DEBUG_INFO("chargingProfileId Found\n");
  8973. }
  8974. memset(word, 0, ARRAY_SIZE(word));
  8975. }
  8976. fclose(fptr1);
  8977. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8978. }
  8979. }
  8980. //Check TxProfile_%d.json
  8981. for(int j=1; j <= gunTotalNumber; j++)
  8982. {
  8983. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8984. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8985. if((access(fnametemp,F_OK))!=-1)
  8986. {
  8987. i = 0;
  8988. fptr1 = fopen(fnametemp, "r");
  8989. //Check Charging Profile Count
  8990. while(fscanf(fptr1, "%s", word) != EOF)
  8991. {
  8992. //DEBUG_INFO("word=%s\n",word);
  8993. if(strstr(word, "chargingProfileId")!= NULL)
  8994. {
  8995. //DEBUG_INFO("test chargingProfileId \n");
  8996. n_chargingProfile = n_chargingProfile + 1;
  8997. i = i + 1;
  8998. //DEBUG_INFO("chargingProfileId Found\n");
  8999. }
  9000. memset(word, 0, ARRAY_SIZE(word));
  9001. }
  9002. fclose(fptr1);
  9003. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9004. }
  9005. }
  9006. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9007. {
  9008. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9009. goto end;
  9010. }
  9011. }
  9012. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9013. //**********************************Write to File********************************************************/
  9014. FILE *infile;
  9015. FILE *outfile;
  9016. infile = fopen (filename, "r");
  9017. outfile = fopen (tempfile, "w");
  9018. int d =0;
  9019. d = fgetc(infile);
  9020. rewind(infile);
  9021. if(d == EOF)
  9022. {
  9023. // Profile is empty
  9024. fprintf(outfile,"%s\n",payload);
  9025. fclose(infile);
  9026. fclose(outfile);
  9027. sprintf(rmFileCmd,"rm -f %s",filename);
  9028. system(rmFileCmd);
  9029. rename(tempfile, filename);
  9030. }
  9031. else
  9032. {
  9033. // Profile is not empty
  9034. char buf[2048]={0};
  9035. int ChargingProfileAdded = FALSE;
  9036. while (fgets(buf, sizeof(buf), infile) != NULL)
  9037. {
  9038. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9039. json_object *tmpChargingProfile;
  9040. tmpChargingProfile = json_tokener_parse(buf);
  9041. if(!is_error(SetChargingProfile))
  9042. {
  9043. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9044. {
  9045. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9046. }
  9047. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9048. {
  9049. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9050. {
  9051. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9052. }
  9053. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9054. {
  9055. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9056. }
  9057. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9058. {
  9059. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9060. }
  9061. }
  9062. }
  9063. json_object_put(tmpChargingProfile);
  9064. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9065. {
  9066. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9067. {
  9068. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9069. if(ChargingProfileAdded == FALSE)
  9070. {
  9071. fprintf(outfile,"%s\n",payload);
  9072. ChargingProfileAdded = TRUE;
  9073. }
  9074. }
  9075. else
  9076. {
  9077. if(tempstackLevelInt < stackLevelInt)
  9078. {
  9079. if(ChargingProfileAdded == FALSE)
  9080. {
  9081. fprintf(outfile,"%s\n",buf);
  9082. fprintf(outfile,"%s\n",payload);
  9083. ChargingProfileAdded = TRUE;
  9084. }
  9085. else
  9086. {
  9087. fprintf(outfile,"%s\n",buf);
  9088. }
  9089. }
  9090. else
  9091. {
  9092. if(ChargingProfileAdded == FALSE)
  9093. {
  9094. fprintf(outfile,"%s\n",buf);
  9095. fprintf(outfile,"%s\n",payload);
  9096. ChargingProfileAdded = TRUE;
  9097. }
  9098. else
  9099. {
  9100. fprintf(outfile,"%s\n",buf);
  9101. }
  9102. }
  9103. }
  9104. }
  9105. else
  9106. {
  9107. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9108. {
  9109. if(ChargingProfileAdded == FALSE)
  9110. {
  9111. fprintf(outfile,"%s\n",buf);
  9112. fprintf(outfile,"%s\n",payload);
  9113. ChargingProfileAdded = TRUE;
  9114. }
  9115. else
  9116. {
  9117. fprintf(outfile,"%s\n",buf);
  9118. }
  9119. }
  9120. else if(tempstackLevelInt < stackLevelInt)
  9121. {
  9122. if(ChargingProfileAdded == FALSE)
  9123. {
  9124. fprintf(outfile,"%s\n",buf);
  9125. fprintf(outfile,"%s\n",payload);
  9126. ChargingProfileAdded = TRUE;
  9127. }
  9128. else
  9129. {
  9130. fprintf(outfile,"%s\n",buf);
  9131. }
  9132. }
  9133. else
  9134. {
  9135. if(ChargingProfileAdded == FALSE)
  9136. {
  9137. fprintf(outfile,"%s\n",buf);
  9138. fprintf(outfile,"%s\n",payload);
  9139. ChargingProfileAdded = TRUE;
  9140. }
  9141. else
  9142. {
  9143. fprintf(outfile,"%s\n",buf);
  9144. }
  9145. }
  9146. }
  9147. } // end of while loop
  9148. fclose(infile);
  9149. fclose(outfile);
  9150. sprintf(rmFileCmd,"rm -f %s",filename);
  9151. system(rmFileCmd);
  9152. rename(tempfile, filename);
  9153. }
  9154. sleep(1);
  9155. result = TRUE;
  9156. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9157. end:
  9158. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9159. {
  9160. if(connectorIdInt == 0)
  9161. {
  9162. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9163. {
  9164. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9165. }
  9166. }
  9167. else
  9168. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9169. }
  9170. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9171. return result;
  9172. }
  9173. int handleTriggerMessageRequest(char *uuid, char *payload)
  9174. {
  9175. mtrace();
  9176. int result = FAIL;
  9177. int connectorIdIsNULL = FALSE;
  9178. int connectorIdInt =0;
  9179. char sstr[40]={0},sstrtemp[100]={ 0 };
  9180. char requestedMessagestr[40]={0};
  9181. char comfirmstr[20]={0};
  9182. int c = 0;
  9183. char *loc;
  9184. DEBUG_INFO("handleTriggerMessageRequest\n");
  9185. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9186. strcpy(sstrtemp, stringtrimspace(payload));
  9187. c = 0;
  9188. loc = strstr(sstrtemp, "requestedMessage");
  9189. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9190. {
  9191. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9192. c++;
  9193. }
  9194. sstr[c] = '\0';
  9195. strcpy(requestedMessagestr, sstr);
  9196. c = 0;
  9197. loc = strstr(sstrtemp, "connectorId");
  9198. if(loc == NULL)
  9199. {
  9200. connectorIdIsNULL = TRUE;
  9201. }
  9202. else
  9203. {
  9204. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9205. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9206. {
  9207. sstr[c] = loc[strlen("connectorId")+2+c];
  9208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9209. c++;
  9210. }
  9211. sstr[c] = '\0';
  9212. connectorIdInt = atoi(sstr);
  9213. }
  9214. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9215. {
  9216. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9217. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9218. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9219. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9220. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9221. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9222. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9223. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9224. {
  9225. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9226. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9227. return TRUE;
  9228. }
  9229. else
  9230. {
  9231. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9232. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9233. }
  9234. }
  9235. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9236. {
  9237. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9238. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9239. return TRUE;
  9240. }
  9241. //==========================
  9242. // Trigger message
  9243. //==========================
  9244. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9245. {
  9246. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9247. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9248. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9249. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9250. {
  9251. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9252. }
  9253. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9254. }
  9255. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9256. {
  9257. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9258. }
  9259. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9260. {
  9261. //sendBootNotificationRequest();
  9262. server_sign = FALSE;
  9263. }
  9264. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9265. {
  9266. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9267. }
  9268. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9269. {
  9270. if(connectorIdIsNULL == FALSE)
  9271. {
  9272. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9273. {
  9274. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9275. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9276. }
  9277. }
  9278. else
  9279. {
  9280. for(int idx=0;idx< gunTotalNumber;idx++)
  9281. {
  9282. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9283. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9284. }
  9285. }
  9286. }
  9287. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9288. {
  9289. if(connectorIdIsNULL == FALSE)
  9290. {
  9291. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9292. {
  9293. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9294. }
  9295. }
  9296. else
  9297. {
  9298. for(int idx=0;idx< gunTotalNumber;idx++)
  9299. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9300. }
  9301. }
  9302. return result;
  9303. }
  9304. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9305. {
  9306. mtrace();
  9307. int result = FAIL;
  9308. int connectorIdInt =0;
  9309. char comfirmstr[20]={0};
  9310. int tempIndex = 0;
  9311. json_object *UnlockConnector;
  9312. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9313. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9314. UnlockConnector = json_tokener_parse(payload);
  9315. if(!is_error(UnlockConnector))
  9316. {
  9317. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9318. {
  9319. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9320. }
  9321. }
  9322. json_object_put(UnlockConnector);
  9323. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9324. if(gunTotalNumber == 0)
  9325. {
  9326. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9327. goto end;
  9328. }
  9329. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9330. {
  9331. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9332. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9333. goto end;
  9334. }
  9335. else
  9336. {
  9337. //check Transaction active
  9338. if(gunType[connectorIdInt-1] == 'J')
  9339. {
  9340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9341. {
  9342. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9343. }
  9344. else
  9345. {
  9346. tempIndex = connectorIdInt -1;
  9347. }
  9348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9349. {
  9350. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9351. {
  9352. //stop Transaction
  9353. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9354. }
  9355. }
  9356. }
  9357. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9358. {
  9359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9360. {
  9361. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9362. }
  9363. else
  9364. {
  9365. tempIndex = connectorIdInt -1;
  9366. }
  9367. for (int index = 0; index < CCS_QUANTITY; index++)
  9368. {
  9369. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9370. {
  9371. //stop Transaction
  9372. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9373. }
  9374. }
  9375. }
  9376. else if(gunType[connectorIdInt-1] == 'G')
  9377. {
  9378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9379. {
  9380. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9381. }
  9382. else
  9383. {
  9384. tempIndex = connectorIdInt -1;
  9385. }
  9386. for (int index = 0; index < GB_QUANTITY; index++)
  9387. {
  9388. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9389. {
  9390. //stop Transaction
  9391. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9392. }
  9393. }
  9394. }
  9395. else if(gunType[connectorIdInt-1] == 'O')
  9396. {
  9397. tempIndex = connectorIdInt -1;
  9398. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9399. {
  9400. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  9401. {
  9402. //stop Transaction
  9403. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9404. }
  9405. }
  9406. }
  9407. else
  9408. {
  9409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9410. {
  9411. tempIndex = 2;
  9412. }
  9413. else
  9414. {
  9415. tempIndex = connectorIdInt-1;
  9416. }
  9417. for (int index = 0; index < AC_QUANTITY; index++)
  9418. {
  9419. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9420. {
  9421. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9422. }
  9423. }
  9424. }
  9425. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9426. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9427. result = TRUE;
  9428. return result;
  9429. }
  9430. end:
  9431. //json_object_put(obj); --- remove temporally
  9432. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9433. return result;
  9434. }
  9435. static char UpdateFirmwarepayloadData[300]={0};
  9436. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9437. {
  9438. mtrace();
  9439. int result = FAIL;
  9440. pthread_t t;
  9441. sendUpdateFirmwareConfirmation(uuid);
  9442. memset(UpdateFirmwarepayloadData, 0, 300);
  9443. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9444. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9445. ////pthread_join(t, NULL); //
  9446. //pthread_detach(t);
  9447. //sendUpdateFirmwareConfirmation(uuid);
  9448. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9449. return result;
  9450. }
  9451. void *UpdateFirmwareProcess(void *data)
  9452. {
  9453. pthread_detach(pthread_self());
  9454. mtrace();
  9455. int retriesInt =0, retryIntervalInt=0;
  9456. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9457. int port=0;
  9458. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9459. int isSuccess = 0;
  9460. char ftpbuf[200];
  9461. char temp[100];
  9462. char * pch;
  9463. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9464. json_object *UpdateFirmware;
  9465. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9466. if(!is_error(UpdateFirmware))
  9467. {
  9468. // Required data
  9469. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9470. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9471. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9472. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9473. // Optional data
  9474. if(json_object_object_get(UpdateFirmware, "retries"))
  9475. {
  9476. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9477. }
  9478. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9479. {
  9480. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9481. }
  9482. }
  9483. json_object_put(UpdateFirmware);
  9484. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9485. memset(path, 0, ARRAY_SIZE(path));
  9486. system("rm -f /mnt/*");
  9487. if(strncmp(locationstr,"http", 4) == 0)
  9488. {
  9489. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9490. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9491. // protocol, user, password, host, path);
  9492. sprintf(ftppath,"/%s", path);
  9493. DEBUG_INFO("locationstr: %s\n", locationstr);
  9494. DEBUG_INFO("protocol: %s\n",protocol);
  9495. DEBUG_INFO("host: %s\n",host);
  9496. DEBUG_INFO("path: %s\n",path);
  9497. DEBUG_INFO("ftppath: %s\n",ftppath);
  9498. int ftppathlen=strlen(ftppath);
  9499. int i=1;
  9500. char filenametemp[50];
  9501. while(i < ftppathlen)
  9502. {
  9503. int len=ftppathlen-i;
  9504. if(ftppath[len]== 47) // '/' ascll code: 47
  9505. {
  9506. DEBUG_INFO("compare '/' all right\n");
  9507. break;
  9508. }
  9509. i=i+1;
  9510. }
  9511. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9512. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9513. filenametemp[i+1] = 0;
  9514. do
  9515. {
  9516. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9517. sleep(3);
  9518. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9519. if(!isSuccess)
  9520. {
  9521. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9522. sleep(retryIntervalInt);
  9523. }
  9524. else
  9525. {
  9526. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9527. }
  9528. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9529. }
  9530. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9531. {
  9532. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9533. memset(temp, 0, ARRAY_SIZE(temp));
  9534. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9535. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9536. int ftppathlen=strlen(ftpbuf);
  9537. int i=1;
  9538. char filenametemp[50];
  9539. while(i < ftppathlen)
  9540. {
  9541. int len=ftppathlen-i;
  9542. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9543. {
  9544. DEBUG_INFO(" compare '/' all right\n");
  9545. break;
  9546. }
  9547. i=i+1;
  9548. }
  9549. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9550. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9551. filenametemp[i+1] = 0;
  9552. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9553. pch=strchr(temp,'@');
  9554. if(pch==NULL)
  9555. {
  9556. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9557. protocol, host, &port, path);
  9558. strcpy(user,"anonymous");
  9559. strcpy(password,"");
  9560. }
  9561. else
  9562. {
  9563. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9564. protocol, user, password, host, &port, path);
  9565. }
  9566. sscanf(host,"%[^/]%s",host1, path1);
  9567. sprintf(ftppath,"%s", path1);
  9568. //DEBUG_INFO("protocol =%s\n",protocol);
  9569. //DEBUG_INFO("user =%s\n",user);
  9570. //DEBUG_INFO("password =%s\n",password);
  9571. //DEBUG_INFO("host1 =%s\n",host1);
  9572. //DEBUG_INFO("port =%d\n",port);
  9573. //DEBUG_INFO("path1 =%s\n",path1);
  9574. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9575. //ftpFile(host, user, password, port, ftppath, fname);
  9576. //download firmware pthred
  9577. if(port == 0)
  9578. {
  9579. port = 21;
  9580. }
  9581. do
  9582. {
  9583. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9584. sleep(3);
  9585. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9586. if(!isSuccess)
  9587. {
  9588. //BulldogUtil.sleepMs(interval*1000);
  9589. DEBUG_INFO("Update firmware request and download file fail.\n");
  9590. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9591. sleep(retryIntervalInt);
  9592. }
  9593. else
  9594. {
  9595. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9596. }
  9597. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9598. }
  9599. else
  9600. {
  9601. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9602. }
  9603. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9604. pthread_exit(NULL);
  9605. }
  9606. //==========================================
  9607. // Handle server response routine
  9608. //==========================================
  9609. void handleAuthorizeResponse(char *payload, int gun_index)
  9610. {
  9611. mtrace();
  9612. char expiryDatestr[30]={0};
  9613. char parentIdTagstr[20]={0};
  9614. char statusstr[20]={0};
  9615. char expiryDatestrtemp[30]={0};
  9616. char parentIdTagstrtemp[20]={0};
  9617. char IdTagstrtemp[20]={0};
  9618. char statusstrtemp[20]={0};
  9619. int expiryDateISNULL=FALSE;
  9620. int parentIdTagISNULL=FALSE;
  9621. char sstr[160]={0};
  9622. char* filename = AuthorizationCache_JSON;
  9623. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9624. char *loc;
  9625. int resultRename=0;
  9626. int responseIdTagInfoAsZero= 0;
  9627. char rmFileCmd[50]={0};
  9628. DEBUG_INFO("handleAuthorizeResponse...\n");
  9629. json_object *Authorize;
  9630. Authorize = json_tokener_parse(payload);
  9631. if(!is_error(Authorize))
  9632. {
  9633. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9634. {
  9635. // Required data
  9636. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9637. // Optional data
  9638. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9639. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9640. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9641. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9642. }
  9643. }
  9644. json_object_put(Authorize);
  9645. if(expiryDateISNULL == FALSE)
  9646. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9647. if(parentIdTagISNULL == FALSE)
  9648. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9649. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9650. //Update idTag information to authorization cache if supproted
  9651. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9652. {
  9653. if((access(filename,F_OK))!=-1)
  9654. {
  9655. printf("AuthorizationCache exist.\n");
  9656. }
  9657. else
  9658. {
  9659. printf("AuthorizationCache not exist\n");
  9660. FILE *log = fopen(filename, "w+");
  9661. if(log == NULL)
  9662. {
  9663. printf("log is NULL\n");
  9664. goto out;
  9665. }
  9666. else
  9667. {
  9668. fclose(log);
  9669. }
  9670. }
  9671. FILE *infile;
  9672. FILE *outfile;
  9673. // open file for writing
  9674. infile = fopen (filename, "r");
  9675. outfile = fopen (tempfile, "w");
  9676. int c;
  9677. c = fgetc(infile);
  9678. //DEBUG_INFO("c:%d\n",c);
  9679. rewind(infile);
  9680. if(c == EOF)
  9681. {
  9682. DEBUG_INFO("Orignal File is NULL\n");
  9683. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9684. {
  9685. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9686. }
  9687. else
  9688. {
  9689. strcpy(expiryDatestrtemp, "");
  9690. }
  9691. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9692. {
  9693. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9694. }
  9695. else
  9696. {
  9697. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9698. }
  9699. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9700. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9701. fclose(infile);
  9702. fclose(outfile);
  9703. sprintf(rmFileCmd,"rm -f %s",filename);
  9704. system(rmFileCmd);
  9705. resultRename = rename(tempfile, filename);
  9706. if(resultRename == 0)
  9707. {
  9708. printf("File renamed successfully");
  9709. }
  9710. else
  9711. {
  9712. printf("Error: unable to rename the file");
  9713. }
  9714. }
  9715. else
  9716. {
  9717. char buf[160]={0};
  9718. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9719. {
  9720. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9721. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9722. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9723. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9724. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9725. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9726. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9727. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9728. //------------------IdTag-----------------------
  9729. loc = strstr(buf, "idTag");
  9730. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9731. c = 0;
  9732. while (loc[3+strlen("idTag")+c] != '\"')
  9733. {
  9734. sstr[c] = loc[3+strlen("idTag")+c];
  9735. c++;
  9736. }
  9737. sstr[c] = '\0';
  9738. strcpy(IdTagstrtemp,sstr);
  9739. //*********************expiryDate***************/
  9740. loc = strstr(buf, "expiryDate");
  9741. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9742. c = 0;
  9743. while (loc[3+strlen("expiryDate")+c] != '\"')
  9744. {
  9745. sstr[c] = loc[3+strlen("expiryDate")+c];
  9746. c++;
  9747. }
  9748. sstr[c] = '\0';
  9749. strcpy(expiryDatestr,sstr);
  9750. //*********************parentIdTag***************/
  9751. loc = strstr(buf, "parentIdTag");
  9752. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9753. c = 0;
  9754. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9755. {
  9756. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9757. c++;
  9758. }
  9759. sstr[c] = '\0';
  9760. strcpy(parentIdTagstr,sstr);
  9761. //*********************status***************/
  9762. loc = strstr(buf, "status");
  9763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9764. c = 0;
  9765. while (loc[3+strlen("status")+c] != '\"')
  9766. {
  9767. sstr[c] = loc[3+strlen("status")+c];
  9768. c++;
  9769. }
  9770. sstr[c] = '\0';
  9771. strcpy(statusstr,sstr);
  9772. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9773. {
  9774. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9775. responseIdTagInfoAsZero = 1;
  9776. }
  9777. else
  9778. {
  9779. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9780. }
  9781. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9782. {
  9783. //modify item
  9784. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9785. {
  9786. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9787. }
  9788. else
  9789. {
  9790. strcpy(expiryDatestrtemp, "");
  9791. }
  9792. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9793. {
  9794. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9795. }
  9796. else
  9797. {
  9798. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9799. }
  9800. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9801. }
  9802. else
  9803. {
  9804. //wrie original item
  9805. strcpy(expiryDatestrtemp, expiryDatestr);
  9806. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9807. strcpy(statusstrtemp, statusstr);
  9808. }
  9809. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9810. }
  9811. fclose(infile);
  9812. fclose(outfile);
  9813. sprintf(rmFileCmd,"rm -f %s",filename);
  9814. system(rmFileCmd);
  9815. resultRename = rename(tempfile, filename);
  9816. if(resultRename == 0)
  9817. {
  9818. DEBUG_INFO("File renamed successfully");
  9819. }
  9820. else
  9821. {
  9822. DEBUG_INFO("Error: unable to rename the file");
  9823. }
  9824. }
  9825. }
  9826. out:
  9827. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9828. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9829. authorizeRetryTimes = 0;
  9830. }
  9831. void handleBootNotificationResponse(char *payload, int gun_index)
  9832. {
  9833. mtrace();
  9834. char statusStr[12]={0};
  9835. char currentTimeStr[30]={0};
  9836. int intervalInt = 0;
  9837. struct tm tp;
  9838. char buf[28]={0};
  9839. char timebuf[50]={0};
  9840. DEBUG_INFO("handleBootNotificationResponse...\n");
  9841. json_object *BootNotification;
  9842. BootNotification = json_tokener_parse(payload);
  9843. if(!is_error(BootNotification))
  9844. {
  9845. // Required data
  9846. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9847. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9848. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9849. }
  9850. json_object_put(BootNotification);
  9851. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9852. BootNotificationInterval = intervalInt;
  9853. HeartBeatWaitTime = intervalInt;
  9854. //write back to ShmOCPP16Data->BootNotification
  9855. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9856. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9857. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9858. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9859. {
  9860. server_sign = TRUE;
  9861. server_pending =FALSE;
  9862. }
  9863. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9864. {
  9865. server_pending = TRUE;
  9866. }
  9867. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9868. tp.tm_isdst = -1;
  9869. //time_t utc = mktime(&tp);
  9870. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9871. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9872. sprintf(timebuf,"date -s '%s'",buf);
  9873. system(timebuf);
  9874. srand(time(NULL));
  9875. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9876. //==============================================
  9877. // RTC sync
  9878. //==============================================
  9879. system("/sbin/hwclock -w --systohc");
  9880. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9881. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9882. }
  9883. void handleDataTransferResponse(char *payload, int gun_index)
  9884. {
  9885. char sstr[160]={0};//sstr[200]={ 0 };
  9886. int c = 0;
  9887. char *loc;
  9888. DEBUG_INFO("handleDataTransferResponse ...\n");
  9889. loc = strstr(payload, "status");
  9890. printf("loc=%s\n",loc);
  9891. c = 0;
  9892. while (loc[3+strlen("status")+c] != '\"')
  9893. {
  9894. sstr[c] = loc[3+strlen("status")+c];
  9895. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9896. c++;
  9897. }
  9898. sstr[c] = '\0';
  9899. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9900. }
  9901. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9902. {
  9903. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9904. //struct json_object *obj;
  9905. // obj = json_tokener_parse(payload);
  9906. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9907. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9908. //No fields are defined.
  9909. }
  9910. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9911. {
  9912. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9913. //struct json_object *obj;
  9914. // obj = json_tokener_parse(payload);
  9915. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9916. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9917. //No fields are defined.
  9918. }
  9919. void handleHeartbeatResponse(char *payload, int gun_index)
  9920. {
  9921. mtrace();
  9922. struct tm tp;
  9923. char buf[28]={0};
  9924. char timebuf[50]={0};
  9925. DEBUG_INFO("handleHeartbeatResponse...\n");
  9926. json_object *Heartbeat;
  9927. Heartbeat = json_tokener_parse(payload);
  9928. if(!is_error(Heartbeat))
  9929. {
  9930. // Required data
  9931. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9932. }
  9933. json_object_put(Heartbeat);
  9934. if(FirstHeartBeat == 0)
  9935. {
  9936. FirstHeartBeat = 1;
  9937. DEBUG_INFO("FirstHeartBeat \n");
  9938. }
  9939. HeartBeatWithNOResponse = 0;
  9940. clientTime.Heartbeat=time((time_t*)NULL);
  9941. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9942. tp.tm_isdst = -1;
  9943. //time_t utc = mktime(&tp);
  9944. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9945. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9946. sprintf(timebuf,"date -s '%s'",buf);
  9947. system(timebuf);
  9948. //==============================================
  9949. // RTC sync
  9950. //==============================================
  9951. system("/sbin/hwclock -w --systohc");
  9952. }
  9953. void handleMeterValuesResponse(char *payload, int gun_index)
  9954. {
  9955. mtrace();
  9956. DEBUG_INFO("handleMeterValuesResponse...\n");
  9957. }
  9958. void handleStartTransactionResponse(char *payload, int gun_index)
  9959. {
  9960. mtrace();
  9961. //int transactionIdInt = 0;
  9962. FILE *outfile;
  9963. char data[100]={0};
  9964. DEBUG_INFO("handleStartTransactionResponse...\n");
  9965. json_object *StartTransaction;
  9966. StartTransaction = json_tokener_parse(payload);
  9967. if(!is_error(StartTransaction))
  9968. {
  9969. // Required data
  9970. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9971. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9972. // Optional data
  9973. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9974. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9975. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9976. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9977. }
  9978. json_object_put(StartTransaction);
  9979. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9980. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9981. //-----------Start : write to the Queue TransactionId file -----------------//
  9982. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9983. {}
  9984. else
  9985. {
  9986. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9987. if(log == NULL)
  9988. {
  9989. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9990. return ;
  9991. }
  9992. else
  9993. {
  9994. fclose(log);
  9995. }
  9996. }
  9997. // open file for writing
  9998. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9999. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10000. {
  10001. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10002. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10003. fputs(data, outfile);
  10004. fclose (outfile);
  10005. }
  10006. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10007. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10008. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10009. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10010. }
  10011. void handleStatusNotificationResponse(char *payload, int gun_index)
  10012. {
  10013. mtrace();
  10014. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10015. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10016. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10017. }
  10018. void handleStopTransactionnResponse(char *payload, int gun_index)
  10019. {
  10020. mtrace();
  10021. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10022. json_object *StopTransaction;
  10023. StopTransaction = json_tokener_parse(payload);
  10024. if(!is_error(StopTransaction))
  10025. {
  10026. // Optional data
  10027. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10028. {
  10029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10030. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10032. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10034. }
  10035. }
  10036. json_object_put(StopTransaction);
  10037. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10038. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10039. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10040. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10041. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10042. }
  10043. //==========================================
  10044. // Handle Error routine
  10045. //==========================================
  10046. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10047. {
  10048. mtrace();
  10049. #ifdef SystemLogMessage
  10050. DEBUG_INFO("errorCode: %s\n", errorCode);
  10051. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10052. DEBUG_INFO("errorDetails: %s\n", payload);
  10053. #endif
  10054. }
  10055. //===============================================
  10056. // Common routine
  10057. //===============================================
  10058. int initialConfigurationTable(void)
  10059. {
  10060. //clock_t start_t, end_t, total_t;
  10061. FILE *fp;
  10062. FILE *outfile;
  10063. char str[200]={0};
  10064. char sstr[100]={0};
  10065. int c = 0;
  10066. char *loc;
  10067. DEBUG_INFO("initialConfigurationTable...\n");
  10068. //start_t = clock();
  10069. //printf("Starting of the program, start_t = %ld\n", start_t);
  10070. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10071. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10072. {
  10073. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10074. if(outfile == NULL)
  10075. {
  10076. DEBUG_INFO("Error opening file\n");
  10077. return FALSE;
  10078. }
  10079. /*Core Profile*/
  10080. //AllowOfflineTxForUnknownId
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10085. //AuthorizationCacheEnabled
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10090. //AuthorizeRemoteTxRequests
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10095. //BlinkRepeat
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10100. //ClockAlignedDataInterval
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10105. //ConnectionTimeOut
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10110. //GetConfigurationMaxKeys
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10115. // HeartbeatInterval
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10120. // LightIntensity
  10121. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10125. // LocalAuthorizeOffline
  10126. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10130. // LocalPreAuthorize
  10131. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10135. // MaxEnergyOnInvalidId
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10139. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10141. // MeterValuesAlignedData
  10142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10146. else
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10149. // MeterValuesAlignedDataMaxLength
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10154. else
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10157. // MeterValuesSampledData
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10162. else
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10165. // MeterValuesSampledDataMaxLength
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10170. else
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10173. // MeterValueSampleInterval
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10178. // MinimumStatusDuration
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10182. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10184. // NumberOfConnectors
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10188. {
  10189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10190. }
  10191. else
  10192. {
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10194. }
  10195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10196. // ResetRetries
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10201. // ConnectorPhaseRotation
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10206. // ConnectorPhaseRotationMaxLength
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10211. // StopTransactionOnEVSideDisconnect
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10216. // StopTransactionOnInvalidId
  10217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10221. // StopTxnAlignedData
  10222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10226. // StopTxnAlignedDataMaxLength
  10227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10231. // StopTxnSampledData
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10234. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10236. else
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10239. // StopTxnSampledDataMaxLength
  10240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10243. {
  10244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10245. }
  10246. else
  10247. {
  10248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10249. }
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10251. // SupportedFeatureProfiles
  10252. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10256. // SupportedFeatureProfilesMaxLength
  10257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10261. // TransactionMessageAttempts
  10262. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10265. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10267. // TransactionMessageRetryInterval
  10268. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10271. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10273. // UnlockConnectorOnEVSideDisconnect
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10278. // WebSocketPingInterval
  10279. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10283. // QueueOffLineStartTransactionMessage
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10288. // AuthorizationKey
  10289. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10293. // SecurityProfile
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10298. // DefaultPrice
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10303. // CustomDisplayCostAndPrice
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10308. // CustomIdleFeeAfterStop
  10309. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10313. //* Local Auth List Management Profile*/
  10314. #if 0
  10315. //For OCTT Test Case
  10316. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10319. #endif
  10320. #if 1
  10321. //LocalAuthListEnabled
  10322. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10326. #endif
  10327. //LocalAuthListMaxLength
  10328. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10332. //SendLocalListMaxLength
  10333. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10337. //ReserveConnectorZeroSupported
  10338. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10342. //* Smart Charging Profile */
  10343. //ChargeProfileMaxStackLevel
  10344. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10348. // ChargingScheduleAllowedChargingRateUnit
  10349. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10353. // ChargingScheduleMaxPeriods
  10354. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10358. // ConnectorSwitch3to1PhaseSupported
  10359. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10363. // MaxChargingProfilesInstalled
  10364. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10368. fclose(outfile);
  10369. }
  10370. else
  10371. {
  10372. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10373. char keystr[60]={0};
  10374. char readonlystr[10]={0};
  10375. char valuestr[100]={0};
  10376. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10377. if(fp == NULL) {
  10378. DEBUG_INFO("Error opening file");
  10379. return FALSE;
  10380. }
  10381. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10382. {
  10383. //DEBUG_INFO("Get Configuration \n");
  10384. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10385. //*************************key*********************************/
  10386. loc = strstr(str, "key");
  10387. c = 0;
  10388. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10389. while (loc[strlen("key")+3+c] != '\"')
  10390. {
  10391. sstr[c] = loc[strlen("key")+3+c];
  10392. c++;
  10393. }
  10394. sstr[c] = '\0';
  10395. strcpy(keystr,sstr);
  10396. //*************************readonly*********************************/
  10397. loc = strstr(str, "readonly");
  10398. c = 0;
  10399. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10400. while (loc[strlen("readonly")+2+c] != ',')
  10401. {
  10402. sstr[c] = loc[strlen("readonly")+2+c];
  10403. c++;
  10404. }
  10405. sstr[c] = '\0';
  10406. strcpy(readonlystr,sstr);
  10407. //*************************value*********************************/
  10408. loc = strstr(str, "value");
  10409. c = 0;
  10410. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10411. while (loc[strlen("value")+3+c] != '\"')
  10412. {
  10413. sstr[c] = loc[strlen("value")+3+c];
  10414. c++;
  10415. }
  10416. sstr[c] = '\0';
  10417. strcpy(valuestr,sstr);
  10418. // DEBUG_INFO("keystr=%s\n",keystr);
  10419. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10420. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10421. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10422. {
  10423. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10426. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10427. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10428. }
  10429. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10430. {
  10431. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10434. }
  10435. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10436. {
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10439. }
  10440. if(strcmp(keystr, "BlinkRepeat") == 0)
  10441. {
  10442. //Charger.BlinkRepeat = Integer.parseInt(value);
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10445. }
  10446. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10447. {
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10450. }
  10451. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10452. {
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10455. }
  10456. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10457. {
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10460. }
  10461. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10462. {
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10465. HeartBeatWaitTime = atoi(valuestr);
  10466. }
  10467. if(strcmp(keystr, "LightIntensity") == 0)
  10468. {
  10469. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10471. }
  10472. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10473. {
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10476. }
  10477. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10478. {
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10481. }
  10482. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10483. {
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10486. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10487. }
  10488. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10489. {
  10490. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10492. }
  10493. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10494. {
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10497. }
  10498. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10499. {
  10500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10502. }
  10503. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10504. {
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10507. }
  10508. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10509. {
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10512. }
  10513. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10514. {
  10515. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10517. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10518. }
  10519. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10520. {
  10521. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10523. }
  10524. if(strcmp(keystr, "ResetRetries") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10528. }
  10529. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10533. }
  10534. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10538. }
  10539. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10543. }
  10544. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10548. }
  10549. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10553. }
  10554. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10558. }
  10559. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10563. }
  10564. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10568. }
  10569. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10573. }
  10574. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10575. {
  10576. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10578. }
  10579. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10580. {
  10581. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10583. TransactionMessageAttemptsValue = atoi(valuestr);
  10584. }
  10585. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10586. {
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10589. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10590. }
  10591. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10592. {
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10595. }
  10596. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10600. }
  10601. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10605. }
  10606. if(strcmp(keystr, "AuthorizationKey") == 0)
  10607. {
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10610. }
  10611. if(strcmp(keystr, "SecurityProfile") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10615. }
  10616. if(strcmp(keystr, "DefaultPrice") == 0)
  10617. {
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10620. }
  10621. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10622. {
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10625. }
  10626. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10627. {
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10630. }
  10631. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10632. {
  10633. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10635. }
  10636. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10637. {
  10638. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10640. }
  10641. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10642. {
  10643. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10645. }
  10646. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10647. {
  10648. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10650. }
  10651. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10652. {
  10653. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10655. }
  10656. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10657. {
  10658. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10660. }
  10661. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10662. {
  10663. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10665. }
  10666. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10667. {
  10668. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10670. }
  10671. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10672. {
  10673. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10675. }
  10676. }
  10677. fclose(fp);
  10678. }
  10679. return 0;
  10680. }
  10681. void StoreConfigurationTable(void)
  10682. {
  10683. FILE *outfile;
  10684. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10685. if(outfile == NULL)
  10686. {
  10687. DEBUG_INFO("Error opening file");
  10688. return ;
  10689. }
  10690. /*Core Profile*/
  10691. //AllowOfflineTxForUnknownId
  10692. /*
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10694. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10697. */
  10698. //DEBUG_INFO("data=%s\n",data);
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10700. //AuthorizationCacheEnabled
  10701. /*
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10705. */
  10706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10707. //AuthorizeRemoteTxRequests
  10708. /*
  10709. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10712. */
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10714. //BlinkRepeat
  10715. /*
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10719. */
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10721. //ClockAlignedDataInterval
  10722. /*
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10726. */
  10727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10728. //ConnectionTimeOut
  10729. /*
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10733. */
  10734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10735. //GetConfigurationMaxKeys
  10736. /*
  10737. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10740. */
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10742. // HeartbeatInterval
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10749. // LightIntensity
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10754. */
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10756. // LocalAuthorizeOffline
  10757. /*
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10761. */
  10762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10763. // LocalPreAuthorize
  10764. /*
  10765. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10768. */
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10770. // MaxEnergyOnInvalidId
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10775. */
  10776. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10778. // MeterValuesAlignedData
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10785. // MeterValuesAlignedDataMaxLength
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10792. // MeterValuesSampledData
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10799. // MeterValuesSampledDataMaxLength
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10804. */
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10806. // MeterValueSampleInterval
  10807. /*
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10811. */
  10812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10813. // MinimumStatusDuration
  10814. /*
  10815. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10818. */
  10819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10820. // NumberOfConnectors
  10821. /*
  10822. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10825. {
  10826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10827. }
  10828. else
  10829. {
  10830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10831. }
  10832. */
  10833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10834. // ResetRetries
  10835. /*
  10836. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10839. */
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10841. // ConnectorPhaseRotation
  10842. /*
  10843. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10846. */
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10848. // ConnectorPhaseRotationMaxLength
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10853. */
  10854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10855. // StopTransactionOnEVSideDisconnect
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10862. // StopTransactionOnInvalidId
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10869. // StopTxnAlignedData
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10876. // StopTxnAlignedDataMaxLength
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10883. // StopTxnSampledData
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10890. // StopTxnSampledDataMaxLength
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10897. // SupportedFeatureProfiles
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10904. // SupportedFeatureProfilesMaxLength
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10911. // TransactionMessageAttempts
  10912. /*
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10916. */
  10917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10918. // TransactionMessageRetryInterval
  10919. /*
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10923. */
  10924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10925. // UnlockConnectorOnEVSideDisconnect
  10926. /*
  10927. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10930. */
  10931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10932. // WebSocketPingInterval
  10933. /*
  10934. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10937. */
  10938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10939. // QueueOffLineStartTransactionMessage
  10940. /*
  10941. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10944. */
  10945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10946. // AuthorizationKey
  10947. /*
  10948. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10951. */
  10952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10953. // SecurityProfile
  10954. /*
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10958. */
  10959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10960. // DefaultPrice
  10961. /*
  10962. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10965. */
  10966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10967. // CustomDisplayCostAndPrice
  10968. /*
  10969. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10972. */
  10973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10974. // CustomIdleFeeAfterStop
  10975. /*
  10976. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10979. */
  10980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10981. //* Local Auth List Management Profile*/
  10982. //LocalAuthListEnabled
  10983. /*
  10984. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10987. */
  10988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10989. //LocalAuthListMaxLength
  10990. /*
  10991. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10994. */
  10995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10996. //SendLocalListMaxLength
  10997. /*
  10998. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11001. */
  11002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11003. //ReserveConnectorZeroSupported
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11010. //* Smart Charging Profile */
  11011. //ChargeProfileMaxStackLevel
  11012. /*
  11013. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11016. */
  11017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11018. // ChargingScheduleAllowedChargingRateUnit
  11019. /*
  11020. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11023. */
  11024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11025. // ChargingScheduleMaxPeriods
  11026. /*
  11027. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11030. */
  11031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11032. // ConnectorSwitch3to1PhaseSupported
  11033. /*
  11034. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11037. */
  11038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11039. // MaxChargingProfilesInstalled
  11040. /*
  11041. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11044. */
  11045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11046. fclose(outfile);
  11047. }
  11048. void getKeyValue(char *keyReq)
  11049. {
  11050. int isEmpty = FALSE;
  11051. int isKnowKey = FALSE;
  11052. DEBUG_INFO("keyReq = %s\n", keyReq);
  11053. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11054. isEmpty = TRUE;
  11055. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11062. }
  11063. else
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11066. }
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11068. isKnowKey = TRUE;
  11069. }
  11070. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11077. }
  11078. else
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11081. }
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11083. isKnowKey = TRUE;
  11084. }
  11085. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11092. }
  11093. else
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11096. }
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11098. isKnowKey = TRUE;
  11099. }
  11100. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11107. }
  11108. else
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11111. }
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11113. isKnowKey = TRUE;
  11114. }
  11115. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11122. }
  11123. else
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11126. }
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11128. isKnowKey = TRUE;
  11129. }
  11130. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11137. }
  11138. else
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11141. }
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11143. isKnowKey = TRUE;
  11144. }
  11145. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11152. }
  11153. else
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11156. }
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11158. isKnowKey = TRUE;
  11159. }
  11160. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11167. }
  11168. else
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11171. }
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11173. isKnowKey = TRUE;
  11174. }
  11175. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11182. }
  11183. else
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11186. }
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11188. isKnowKey = TRUE;
  11189. }
  11190. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11197. }
  11198. else
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11201. }
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11203. isKnowKey = TRUE;
  11204. }
  11205. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11212. }
  11213. else
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11216. }
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11218. isKnowKey = TRUE;
  11219. }
  11220. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11227. }
  11228. else
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11231. }
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11233. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11279. isKnowKey = TRUE;
  11280. }
  11281. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11288. }
  11289. else
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11292. }
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11294. isKnowKey = TRUE;
  11295. }
  11296. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11303. }
  11304. else
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11307. }
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11309. isKnowKey = TRUE;
  11310. }
  11311. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11318. }
  11319. else
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11322. }
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11324. isKnowKey = TRUE;
  11325. }
  11326. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11333. }
  11334. else
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11337. }
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11339. isKnowKey = TRUE;
  11340. }
  11341. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11348. }
  11349. else
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11352. }
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11354. isKnowKey = TRUE;
  11355. }
  11356. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11363. }
  11364. else
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11367. }
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11369. isKnowKey = TRUE;
  11370. }
  11371. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11378. }
  11379. else
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11382. }
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11384. isKnowKey = TRUE;
  11385. }
  11386. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11393. }
  11394. else
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11397. }
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11399. isKnowKey = TRUE;
  11400. }
  11401. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11408. }
  11409. else
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11412. }
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11414. isKnowKey = TRUE;
  11415. }
  11416. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11423. }
  11424. else
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11427. }
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11429. isKnowKey = TRUE;
  11430. }
  11431. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11438. }
  11439. else
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11442. }
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11444. isKnowKey = TRUE;
  11445. }
  11446. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11453. }
  11454. else
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11457. }
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11459. isKnowKey = TRUE;
  11460. }
  11461. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11468. }
  11469. else
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11472. }
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11474. isKnowKey = TRUE;
  11475. }
  11476. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11483. }
  11484. else
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11487. }
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11489. isKnowKey = TRUE;
  11490. }
  11491. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11498. }
  11499. else
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11502. }
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11504. isKnowKey = TRUE;
  11505. }
  11506. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11513. }
  11514. else
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11517. }
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11519. isKnowKey = TRUE;
  11520. }
  11521. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11528. }
  11529. else
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11532. }
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11534. isKnowKey = TRUE;
  11535. }
  11536. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11543. }
  11544. else
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11547. }
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11549. isKnowKey = TRUE;
  11550. }
  11551. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11558. }
  11559. else
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11562. }
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11564. isKnowKey = TRUE;
  11565. }
  11566. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11573. }
  11574. else
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11577. }
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11579. isKnowKey = TRUE;
  11580. }
  11581. /*
  11582. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11589. }
  11590. else
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11593. }
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11595. isKnowKey = TRUE;
  11596. }*/
  11597. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11604. }
  11605. else
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11608. }
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11610. isKnowKey = TRUE;
  11611. }
  11612. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11619. }
  11620. else
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11623. }
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11625. isKnowKey = TRUE;
  11626. }
  11627. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11634. }
  11635. else
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11638. }
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11640. isKnowKey = TRUE;
  11641. }
  11642. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11649. }
  11650. else
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11653. }
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11655. isKnowKey = TRUE;
  11656. }
  11657. #if 1
  11658. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11662. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11665. }
  11666. else
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11669. }
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11671. isKnowKey = TRUE;
  11672. }
  11673. #endif
  11674. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11678. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11681. }
  11682. else
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11685. }
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11687. isKnowKey = TRUE;
  11688. }
  11689. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11693. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11696. }
  11697. else
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11700. }
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11702. isKnowKey = TRUE;
  11703. }
  11704. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11708. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11709. {
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11711. }
  11712. else
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11715. }
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11717. isKnowKey = TRUE;
  11718. }
  11719. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11723. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11726. }
  11727. else
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11730. }
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11732. isKnowKey = TRUE;
  11733. }
  11734. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11738. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11741. }
  11742. else
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11745. }
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11747. isKnowKey = TRUE;
  11748. }
  11749. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11754. {
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11756. }
  11757. else
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11760. }
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11762. isKnowKey = TRUE;
  11763. }
  11764. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11768. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11769. {
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11771. }
  11772. else
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11775. }
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11777. isKnowKey = TRUE;
  11778. }
  11779. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11780. {
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11783. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11784. {
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11786. }
  11787. else
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11790. }
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11792. isKnowKey = TRUE;
  11793. }
  11794. //=========================================================
  11795. if(!isEmpty && !isKnowKey)
  11796. {
  11797. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11798. strcpy(unknownkey[UnknownKeynum], keyReq);
  11799. UnknownKeynum = UnknownKeynum + 1;
  11800. }
  11801. }
  11802. void processUnkownKey(void)
  11803. {
  11804. DEBUG_INFO("processUnkownKey...\n");
  11805. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11806. for(int index=0; index < UnknownKeynum; index++)
  11807. {
  11808. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11809. {
  11810. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11811. }
  11812. }
  11813. }
  11814. int setKeyValue(char *key, char *value)
  11815. {
  11816. int isSuccess = NotSupported;
  11817. int check_ascii=0;
  11818. char str[10]={0};
  11819. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11820. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11821. {
  11822. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11824. {
  11825. strcpy(str, (const char*)value);
  11826. for(int i = 0; str[i]; i++){
  11827. str[i] = tolower(str[i]);
  11828. }
  11829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11830. isSuccess = ConfigurationStatus_Accepted;
  11831. }
  11832. else
  11833. {
  11834. isSuccess = ConfigurationStatus_Rejected;
  11835. }
  11836. }
  11837. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11838. {
  11839. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11841. {
  11842. strcpy(str, (const char*)value);
  11843. for(int i = 0; str[i]; i++){
  11844. str[i] = tolower(str[i]);
  11845. }
  11846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11847. isSuccess = ConfigurationStatus_Accepted;
  11848. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11849. }
  11850. else
  11851. {
  11852. isSuccess = ConfigurationStatus_Rejected;
  11853. }
  11854. }
  11855. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11856. {
  11857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11858. {
  11859. strcpy(str, (const char*)value);
  11860. for(int i = 0; str[i]; i++)
  11861. {
  11862. str[i] = tolower(str[i]);
  11863. }
  11864. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11866. isSuccess = ConfigurationStatus_Accepted;
  11867. }
  11868. else
  11869. {
  11870. isSuccess = ConfigurationStatus_Rejected;
  11871. }
  11872. }
  11873. if(strcmp(key, "BlinkRepeat") == 0)
  11874. {
  11875. //Charger.BlinkRepeat = Integer.parseInt(value);
  11876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11877. {
  11878. check_ascii = value[0];
  11879. if( (check_ascii < 48) || (check_ascii > 57) )
  11880. {
  11881. isSuccess = ConfigurationStatus_Rejected;
  11882. }
  11883. else
  11884. {
  11885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11886. isSuccess = ConfigurationStatus_Accepted;
  11887. }
  11888. }
  11889. else
  11890. {
  11891. isSuccess = ConfigurationStatus_Rejected;
  11892. }
  11893. }
  11894. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11895. {
  11896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11897. {
  11898. check_ascii = value[0];
  11899. if( (check_ascii < 48) || (check_ascii > 57) )
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. else
  11904. {
  11905. if((atoi(value) == 0) || (atoi(value) >= 10))
  11906. {
  11907. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11909. isSuccess = ConfigurationStatus_Accepted;
  11910. }
  11911. else
  11912. isSuccess = ConfigurationStatus_Rejected;
  11913. }
  11914. }
  11915. else
  11916. {
  11917. isSuccess = ConfigurationStatus_Rejected;
  11918. }
  11919. }
  11920. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11921. {
  11922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11923. {
  11924. check_ascii = value[0];
  11925. if( (check_ascii < 48) || (check_ascii > 57) )
  11926. {
  11927. isSuccess = ConfigurationStatus_Rejected;
  11928. }
  11929. else
  11930. {
  11931. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11933. isSuccess = ConfigurationStatus_Accepted;
  11934. }
  11935. }
  11936. else
  11937. {
  11938. isSuccess = ConfigurationStatus_Rejected;
  11939. }
  11940. }
  11941. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11942. {
  11943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11944. {
  11945. check_ascii = value[0];
  11946. if( (check_ascii < 48) || (check_ascii > 57) )
  11947. {
  11948. isSuccess = ConfigurationStatus_Rejected;
  11949. }
  11950. else
  11951. {
  11952. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11954. isSuccess = ConfigurationStatus_Accepted;
  11955. }
  11956. }
  11957. else
  11958. {
  11959. isSuccess = ConfigurationStatus_Rejected;
  11960. }
  11961. }
  11962. if(strcmp(key, "HeartbeatInterval") == 0)
  11963. {
  11964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11965. {
  11966. check_ascii = value[0];
  11967. if( (check_ascii < 48) || (check_ascii > 57) )
  11968. {
  11969. isSuccess = ConfigurationStatus_Rejected;
  11970. }
  11971. else
  11972. {
  11973. if((atoi(value) == 0) || (atoi(value) >= 10))
  11974. {
  11975. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11977. HeartBeatWaitTime = atoi(value);
  11978. isSuccess = ConfigurationStatus_Accepted;
  11979. }
  11980. else
  11981. {
  11982. isSuccess = ConfigurationStatus_Rejected;
  11983. }
  11984. }
  11985. }
  11986. else
  11987. {
  11988. isSuccess = ConfigurationStatus_Rejected;
  11989. }
  11990. }
  11991. if(strcmp(key, "LightIntensity") == 0)
  11992. {
  11993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11994. {
  11995. check_ascii = value[0];
  11996. if( (check_ascii < 48) || (check_ascii > 57) )
  11997. {
  11998. isSuccess = ConfigurationStatus_Rejected;
  11999. }
  12000. else
  12001. {
  12002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12003. isSuccess = ConfigurationStatus_Accepted;
  12004. }
  12005. }
  12006. else
  12007. {
  12008. isSuccess = ConfigurationStatus_Rejected;
  12009. }
  12010. }
  12011. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12012. {
  12013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12014. {
  12015. strcpy(str, (const char*)value);
  12016. for(int i = 0; str[i]; i++)
  12017. {
  12018. str[i] = tolower(str[i]);
  12019. }
  12020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12021. isSuccess = ConfigurationStatus_Accepted;
  12022. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "LocalPreAuthorize") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12032. {
  12033. strcpy(str, (const char*)value);
  12034. for(int i = 0; str[i]; i++)
  12035. {
  12036. str[i] = tolower(str[i]);
  12037. }
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. else
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. }
  12046. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12047. {
  12048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12049. {
  12050. check_ascii = value[0];
  12051. if( (check_ascii < 48) || (check_ascii > 57) )
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. else
  12056. {
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12058. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12059. isSuccess = ConfigurationStatus_Accepted;
  12060. }
  12061. }
  12062. else
  12063. {
  12064. isSuccess = ConfigurationStatus_Rejected;
  12065. }
  12066. }
  12067. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12068. {
  12069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12070. {
  12071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12072. isSuccess = ConfigurationStatus_Accepted;
  12073. }
  12074. else
  12075. {
  12076. isSuccess = ConfigurationStatus_Rejected;
  12077. }
  12078. }
  12079. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12080. {
  12081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12082. {
  12083. check_ascii = value[0];
  12084. if( (check_ascii < 48) || (check_ascii > 57) )
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. else
  12089. {
  12090. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12092. isSuccess = ConfigurationStatus_Accepted;
  12093. }
  12094. }
  12095. else
  12096. {
  12097. isSuccess = ConfigurationStatus_Rejected;
  12098. }
  12099. }
  12100. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12101. {
  12102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12103. {
  12104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12105. isSuccess = ConfigurationStatus_Accepted;
  12106. }
  12107. else
  12108. {
  12109. isSuccess = ConfigurationStatus_Rejected;
  12110. }
  12111. }
  12112. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12113. {
  12114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12115. {
  12116. check_ascii = value[0];
  12117. if( (check_ascii < 48) || (check_ascii > 57) )
  12118. {
  12119. isSuccess = ConfigurationStatus_Rejected;
  12120. }
  12121. else
  12122. {
  12123. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12125. isSuccess = ConfigurationStatus_Accepted;
  12126. }
  12127. }
  12128. else
  12129. {
  12130. isSuccess = ConfigurationStatus_Rejected;
  12131. }
  12132. }
  12133. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12134. {
  12135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12136. {
  12137. check_ascii = value[0];
  12138. if( (check_ascii < 48) || (check_ascii > 57) )
  12139. {
  12140. isSuccess = ConfigurationStatus_Rejected;
  12141. }
  12142. else
  12143. {
  12144. if((atoi(value) == 0) || (atoi(value) >= 10))
  12145. {
  12146. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12148. isSuccess = ConfigurationStatus_Accepted;
  12149. }
  12150. else
  12151. {
  12152. isSuccess = ConfigurationStatus_Rejected;
  12153. }
  12154. }
  12155. }
  12156. else
  12157. {
  12158. isSuccess = ConfigurationStatus_Rejected;
  12159. }
  12160. }
  12161. if(strcmp(key, "MinimumStatusDuration") == 0)
  12162. {
  12163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12164. {
  12165. check_ascii = value[0];
  12166. if( (check_ascii < 48) || (check_ascii > 57) )
  12167. {
  12168. isSuccess = ConfigurationStatus_Rejected;
  12169. }
  12170. else
  12171. {
  12172. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12173. {
  12174. isSuccess = ConfigurationStatus_Rejected;
  12175. }
  12176. else
  12177. {
  12178. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12180. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. }
  12184. }
  12185. else
  12186. {
  12187. isSuccess = ConfigurationStatus_Rejected;
  12188. }
  12189. }
  12190. if(strcmp(key, "NumberOfConnectors") == 0)
  12191. {
  12192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12193. {
  12194. check_ascii = value[0];
  12195. if( (check_ascii < 48) || (check_ascii > 57) )
  12196. {
  12197. isSuccess = ConfigurationStatus_Rejected;
  12198. }
  12199. else
  12200. {
  12201. //Charger.ResetRetries = Integer.parseInt(value);
  12202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12203. isSuccess = ConfigurationStatus_Accepted;
  12204. }
  12205. }
  12206. else
  12207. {
  12208. isSuccess = ConfigurationStatus_Rejected;
  12209. }
  12210. }
  12211. if(strcmp(key, "ResetRetries") == 0)
  12212. {
  12213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12214. {
  12215. check_ascii = value[0];
  12216. if( (check_ascii < 48) || (check_ascii > 57) )
  12217. {
  12218. isSuccess = ConfigurationStatus_Rejected;
  12219. }
  12220. else
  12221. {
  12222. //Charger.ResetRetries = Integer.parseInt(value);
  12223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12224. isSuccess = ConfigurationStatus_Accepted;
  12225. }
  12226. }
  12227. else
  12228. {
  12229. isSuccess = ConfigurationStatus_Rejected;
  12230. }
  12231. }
  12232. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12233. {
  12234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12235. {
  12236. strcpy(str, (const char*)value);
  12237. for(int i = 0; str[i]; i++)
  12238. {
  12239. str[i] = tolower(str[i]);
  12240. }
  12241. if(strcmp(str, "notapplicable")== 0)
  12242. {
  12243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12244. isSuccess = ConfigurationStatus_Accepted;
  12245. }
  12246. else if(strcmp(str, "unknown")== 0)
  12247. {
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12249. isSuccess = ConfigurationStatus_Accepted;
  12250. }
  12251. else if(strcmp(str, "rst")== 0)
  12252. {
  12253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12254. isSuccess = ConfigurationStatus_Accepted;
  12255. }
  12256. else if(strcmp(str, "rts")== 0)
  12257. {
  12258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12259. isSuccess = ConfigurationStatus_Accepted;
  12260. }
  12261. else if(strcmp(str, "srt")== 0)
  12262. {
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12264. isSuccess = ConfigurationStatus_Accepted;
  12265. }
  12266. else if(strcmp(str, "str")== 0)
  12267. {
  12268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12269. isSuccess = ConfigurationStatus_Accepted;
  12270. }
  12271. else if(strcmp(str, "trs")== 0)
  12272. {
  12273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12274. isSuccess = ConfigurationStatus_Accepted;
  12275. }
  12276. else if(strcmp(str, "tsr")== 0)
  12277. {
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12279. isSuccess = ConfigurationStatus_Accepted;
  12280. }
  12281. else
  12282. {
  12283. isSuccess = ConfigurationStatus_Rejected;
  12284. }
  12285. }
  12286. else
  12287. {
  12288. isSuccess = ConfigurationStatus_Rejected;
  12289. }
  12290. }
  12291. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12292. {
  12293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12294. {
  12295. check_ascii = value[0];
  12296. if( (check_ascii < 48) || (check_ascii > 57) )
  12297. {
  12298. isSuccess = ConfigurationStatus_Rejected;
  12299. }
  12300. else
  12301. {
  12302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12303. isSuccess = ConfigurationStatus_Accepted;
  12304. }
  12305. }
  12306. else
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. }
  12311. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12312. {
  12313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12314. {
  12315. strcpy(str, (const char*)value);
  12316. for(int i = 0; str[i]; i++)
  12317. {
  12318. str[i] = tolower(str[i]);
  12319. }
  12320. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12322. isSuccess = ConfigurationStatus_Accepted;
  12323. }
  12324. else
  12325. {
  12326. isSuccess = ConfigurationStatus_Rejected;
  12327. }
  12328. }
  12329. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12330. {
  12331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12332. {
  12333. strcpy(str, (const char*)value);
  12334. for(int i = 0; str[i]; i++)
  12335. {
  12336. str[i] = tolower(str[i]);
  12337. }
  12338. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12340. isSuccess = ConfigurationStatus_Accepted;
  12341. }
  12342. else
  12343. {
  12344. isSuccess = ConfigurationStatus_Rejected;
  12345. }
  12346. }
  12347. if(strcmp(key, "StopTxnAlignedData") == 0)
  12348. {
  12349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12350. {
  12351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12352. isSuccess = ConfigurationStatus_Accepted;
  12353. }
  12354. else
  12355. {
  12356. isSuccess = ConfigurationStatus_Rejected;
  12357. }
  12358. }
  12359. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12360. {
  12361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12362. {
  12363. check_ascii = value[0];
  12364. if( (check_ascii < 48) || (check_ascii > 57) )
  12365. {
  12366. isSuccess = ConfigurationStatus_Rejected;
  12367. }
  12368. else
  12369. {
  12370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12371. isSuccess = ConfigurationStatus_Accepted;
  12372. }
  12373. }
  12374. else
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. }
  12379. if(strcmp(key, "StopTxnSampledData") == 0)
  12380. {
  12381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12382. {
  12383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12384. isSuccess = ConfigurationStatus_Accepted;
  12385. }
  12386. else
  12387. {
  12388. isSuccess = ConfigurationStatus_Rejected;
  12389. }
  12390. }
  12391. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12392. {
  12393. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12394. {
  12395. check_ascii = value[0];
  12396. if( (check_ascii < 48) || (check_ascii > 57) )
  12397. {
  12398. isSuccess = ConfigurationStatus_Rejected;
  12399. }
  12400. else
  12401. {
  12402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12403. isSuccess = ConfigurationStatus_Accepted;
  12404. }
  12405. }
  12406. else
  12407. {
  12408. isSuccess = ConfigurationStatus_Rejected;
  12409. }
  12410. }
  12411. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12412. {
  12413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12414. {
  12415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12416. isSuccess = ConfigurationStatus_Accepted;
  12417. }
  12418. else
  12419. {
  12420. isSuccess = ConfigurationStatus_Rejected;
  12421. }
  12422. }
  12423. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12424. {
  12425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12426. {
  12427. check_ascii = value[0];
  12428. if( (check_ascii < 48) || (check_ascii > 57) )
  12429. {
  12430. isSuccess = ConfigurationStatus_Rejected;
  12431. }
  12432. else
  12433. {
  12434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12435. isSuccess = ConfigurationStatus_Accepted;
  12436. }
  12437. }
  12438. else
  12439. {
  12440. isSuccess = ConfigurationStatus_Rejected;
  12441. }
  12442. }
  12443. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12444. {
  12445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12446. {
  12447. check_ascii = value[0];
  12448. if( (check_ascii < 48) || (check_ascii > 57) )
  12449. {
  12450. isSuccess = ConfigurationStatus_Rejected;
  12451. }
  12452. else
  12453. {
  12454. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12456. TransactionMessageAttemptsValue = atoi(value);
  12457. isSuccess = ConfigurationStatus_Accepted;
  12458. }
  12459. }
  12460. else
  12461. {
  12462. isSuccess = ConfigurationStatus_Rejected;
  12463. }
  12464. }
  12465. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12466. {
  12467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12468. {
  12469. check_ascii = value[0];
  12470. if( (check_ascii < 48) || (check_ascii > 57) )
  12471. {
  12472. isSuccess = ConfigurationStatus_Rejected;
  12473. }
  12474. else
  12475. {
  12476. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12478. TransactionMessageRetryIntervalValue = atoi(value);
  12479. isSuccess = ConfigurationStatus_Accepted;
  12480. }
  12481. }
  12482. else
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. }
  12487. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12488. {
  12489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12490. {
  12491. strcpy(str, (const char*)value);
  12492. for(int i = 0; str[i]; i++)
  12493. {
  12494. str[i] = tolower(str[i]);
  12495. }
  12496. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12498. isSuccess = ConfigurationStatus_Accepted;
  12499. }
  12500. else
  12501. {
  12502. isSuccess = ConfigurationStatus_Rejected;
  12503. }
  12504. }
  12505. if(strcmp(key, "WebSocketPingInterval") == 0)
  12506. {
  12507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12508. {
  12509. check_ascii = value[0];
  12510. if( (check_ascii < 48) || (check_ascii > 57) )
  12511. {
  12512. isSuccess = ConfigurationStatus_Rejected;
  12513. }
  12514. else
  12515. {
  12516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12517. isSuccess = ConfigurationStatus_Accepted;
  12518. }
  12519. }
  12520. else
  12521. {
  12522. isSuccess = ConfigurationStatus_Rejected;
  12523. }
  12524. }
  12525. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12526. {
  12527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12528. {
  12529. strcpy(str, (const char*)value);
  12530. for(int i = 0; str[i]; i++)
  12531. {
  12532. str[i] = tolower(str[i]);
  12533. }
  12534. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12536. isSuccess = ConfigurationStatus_Accepted;
  12537. }
  12538. else
  12539. {
  12540. isSuccess = ConfigurationStatus_Rejected;
  12541. }
  12542. }
  12543. if(strcmp(key, "AuthorizationKey") == 0)
  12544. {
  12545. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12546. {
  12547. strcpy(str, (const char*)value);
  12548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12549. isSuccess = ConfigurationStatus_Accepted;
  12550. }
  12551. else
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. }
  12556. if(strcmp(key, "SecurityProfile") == 0)
  12557. {
  12558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12559. {
  12560. check_ascii = value[0];
  12561. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. else if(check_ascii == 0x33)
  12566. {
  12567. isSuccess = NotSupported;
  12568. }
  12569. else
  12570. {
  12571. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12572. {
  12573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12574. isSuccess = ConfigurationStatus_Accepted;
  12575. }
  12576. else
  12577. isSuccess = ConfigurationStatus_Rejected;
  12578. }
  12579. }
  12580. else
  12581. {
  12582. isSuccess = ConfigurationStatus_Rejected;
  12583. }
  12584. }
  12585. if(strcmp(key, "DefaultPrice") == 0)
  12586. {
  12587. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12588. {
  12589. strcpy(str, (const char*)value);
  12590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12591. isSuccess = ConfigurationStatus_Accepted;
  12592. }
  12593. else
  12594. {
  12595. isSuccess = ConfigurationStatus_Rejected;
  12596. }
  12597. }
  12598. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12599. {
  12600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12601. {
  12602. strcpy(str, (const char*)value);
  12603. for(int i = 0; str[i]; i++)
  12604. {
  12605. str[i] = tolower(str[i]);
  12606. }
  12607. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12609. isSuccess = ConfigurationStatus_Accepted;
  12610. }
  12611. else
  12612. {
  12613. isSuccess = ConfigurationStatus_Rejected;
  12614. }
  12615. }
  12616. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12617. {
  12618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12619. {
  12620. strcpy(str, (const char*)value);
  12621. for(int i = 0; str[i]; i++)
  12622. {
  12623. str[i] = tolower(str[i]);
  12624. }
  12625. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12627. isSuccess = ConfigurationStatus_Accepted;
  12628. }
  12629. else
  12630. {
  12631. isSuccess = ConfigurationStatus_Rejected;
  12632. }
  12633. }
  12634. #if 0
  12635. //For OCPP Test Case
  12636. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12637. {
  12638. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12639. {
  12640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12641. isSuccess = ConfigurationStatus_Accepted;
  12642. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12643. }
  12644. else
  12645. {
  12646. isSuccess = ConfigurationStatus_Rejected;
  12647. }
  12648. }
  12649. #endif
  12650. #if 1
  12651. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12652. {
  12653. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12654. {
  12655. strcpy(str, (const char*)value);
  12656. for(int i = 0; str[i]; i++)
  12657. {
  12658. str[i] = tolower(str[i]);
  12659. }
  12660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12661. isSuccess = ConfigurationStatus_Accepted;
  12662. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12663. }
  12664. else
  12665. {
  12666. isSuccess = ConfigurationStatus_Rejected;
  12667. }
  12668. }
  12669. #endif
  12670. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12671. {
  12672. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12673. {
  12674. check_ascii = value[0];
  12675. if( (check_ascii < 48) || (check_ascii > 57) )
  12676. {
  12677. isSuccess = ConfigurationStatus_Rejected;
  12678. }
  12679. else
  12680. {
  12681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12682. isSuccess = ConfigurationStatus_Accepted;
  12683. }
  12684. }
  12685. else
  12686. {
  12687. isSuccess = ConfigurationStatus_Rejected;
  12688. }
  12689. }
  12690. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12691. {
  12692. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12693. {
  12694. check_ascii = value[0];
  12695. if( (check_ascii < 48) || (check_ascii > 57) )
  12696. {
  12697. isSuccess = ConfigurationStatus_Rejected;
  12698. }
  12699. else
  12700. {
  12701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12702. isSuccess = ConfigurationStatus_Accepted;
  12703. }
  12704. }
  12705. else
  12706. {
  12707. isSuccess = ConfigurationStatus_Rejected;
  12708. }
  12709. }
  12710. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12711. {
  12712. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12713. {
  12714. strcpy(str, (const char*)value);
  12715. for(int i = 0; str[i]; i++)
  12716. {
  12717. str[i] = tolower(str[i]);
  12718. }
  12719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12720. isSuccess = ConfigurationStatus_Accepted;
  12721. }
  12722. else
  12723. {
  12724. isSuccess = ConfigurationStatus_Rejected;
  12725. }
  12726. }
  12727. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12728. {
  12729. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12730. {
  12731. check_ascii = value[0];
  12732. if( (check_ascii < 48) || (check_ascii > 57) )
  12733. {
  12734. isSuccess = ConfigurationStatus_Rejected;
  12735. }
  12736. else
  12737. {
  12738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12739. isSuccess = ConfigurationStatus_Accepted;
  12740. }
  12741. }
  12742. else
  12743. {
  12744. isSuccess = ConfigurationStatus_Rejected;
  12745. }
  12746. }
  12747. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12748. {
  12749. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12750. {
  12751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12752. isSuccess = ConfigurationStatus_Accepted;
  12753. }
  12754. else
  12755. {
  12756. isSuccess = ConfigurationStatus_Rejected;
  12757. }
  12758. }
  12759. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12760. {
  12761. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12762. {
  12763. check_ascii = value[0];
  12764. if( (check_ascii < 48) || (check_ascii > 57) )
  12765. {
  12766. isSuccess = ConfigurationStatus_Rejected;
  12767. }
  12768. else
  12769. {
  12770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12771. isSuccess = ConfigurationStatus_Accepted;
  12772. }
  12773. }
  12774. else
  12775. {
  12776. isSuccess = ConfigurationStatus_Rejected;
  12777. }
  12778. }
  12779. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12780. {
  12781. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12782. {
  12783. strcpy(str, (const char*)value);
  12784. for(int i = 0; str[i]; i++)
  12785. {
  12786. str[i] = tolower(str[i]);
  12787. }
  12788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12789. isSuccess = ConfigurationStatus_Accepted;
  12790. }
  12791. else
  12792. {
  12793. isSuccess = ConfigurationStatus_Rejected;
  12794. }
  12795. }
  12796. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12797. {
  12798. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12799. {
  12800. check_ascii = value[0];
  12801. if( (check_ascii < 48) || (check_ascii > 57) )
  12802. {
  12803. isSuccess = ConfigurationStatus_Rejected;
  12804. }
  12805. else
  12806. {
  12807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12808. isSuccess = ConfigurationStatus_Accepted;
  12809. }
  12810. }
  12811. else
  12812. {
  12813. isSuccess = ConfigurationStatus_Rejected;
  12814. }
  12815. }
  12816. return isSuccess;
  12817. }
  12818. int TransactionMessageAttemptsGet(void)
  12819. {
  12820. return TransactionMessageAttemptsValue;
  12821. }
  12822. int FirstHeartBeatResponse(void)
  12823. {
  12824. return FirstHeartBeat;
  12825. }
  12826. int TransactionMessageRetryIntervalGet(void)
  12827. {
  12828. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12829. }
  12830. int ReadHttpStatus(int sock)
  12831. {
  12832. //char c;
  12833. char buff[1024]="",*ptr=buff+1;
  12834. int bytes_received, status;
  12835. DEBUG_INFO("Begin Response ..\n");
  12836. while((bytes_received = recv(sock, ptr, 1, 0))){
  12837. if(bytes_received==-1){
  12838. perror("ReadHttpStatus");
  12839. exit(1);
  12840. }
  12841. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12842. ptr++;
  12843. }
  12844. *ptr=0;
  12845. ptr=buff+1;
  12846. sscanf(ptr,"%*s %d ", &status);
  12847. DEBUG_INFO("%s\n",ptr);
  12848. DEBUG_INFO("status=%d\n",status);
  12849. DEBUG_INFO("End Response ..\n");
  12850. return (bytes_received>0)?status:0;
  12851. }
  12852. //the only filed that it parsed is 'Content-Length'
  12853. int ParseHeader(int sock)
  12854. {
  12855. //char c;
  12856. char buff[1024]="",*ptr=buff+4;
  12857. int bytes_received;
  12858. DEBUG_INFO("Begin HEADER ..\n");
  12859. while((bytes_received = recv(sock, ptr, 1, 0))){
  12860. if(bytes_received==-1){
  12861. perror("Parse Header");
  12862. exit(1);
  12863. }
  12864. if(
  12865. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12866. (ptr[-1]=='\r') && (*ptr=='\n' )
  12867. ) break;
  12868. ptr++;
  12869. }
  12870. *ptr=0;
  12871. ptr=buff+4;
  12872. //printf("%s",ptr);
  12873. if(bytes_received){
  12874. ptr=strstr(ptr,"Content-Length:");
  12875. if(ptr){
  12876. sscanf(ptr,"%*s %d",&bytes_received);
  12877. }else
  12878. bytes_received=-1; //unknown size
  12879. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12880. }
  12881. DEBUG_INFO("End HEADER ..\n");
  12882. return bytes_received ;
  12883. }
  12884. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12885. {
  12886. char rmFileCmd[100]={0};
  12887. char FilePath[100]={0};
  12888. char ftpbuf[200];
  12889. int systemresult;
  12890. //DEBUG_INFO("filename=%s\n",filename);
  12891. //DEBUG_INFO("url=%s\n",url);
  12892. sprintf(FilePath,"/mnt/%s",filename);
  12893. if((access(FilePath,F_OK))!=-1)
  12894. {
  12895. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12896. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12897. system(rmFileCmd);
  12898. }
  12899. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12900. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12901. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12902. systemresult = system(ftpbuf);
  12903. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12904. if(systemresult != 0)
  12905. {
  12906. DEBUG_INFO("http DownLoad error!\n");
  12907. return FALSE;
  12908. }
  12909. return TRUE;
  12910. }
  12911. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12912. {
  12913. char rmFileCmd[100]={0};
  12914. char FilePath[100]={0};
  12915. char ftpbuf[200];
  12916. int systemresult;
  12917. //char temp[100];
  12918. sprintf(FilePath,"/mnt/%s",filename);
  12919. if((access(FilePath,F_OK))!=-1)
  12920. {
  12921. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12922. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12923. system(rmFileCmd);
  12924. }
  12925. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12926. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12927. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12928. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12929. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12930. systemresult = system(ftpbuf);
  12931. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12932. if(systemresult != 0)
  12933. {
  12934. printf("wget error!\n");
  12935. return FALSE;
  12936. }
  12937. return TRUE;
  12938. }
  12939. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12940. {
  12941. char rmFileCmd[100]={0};
  12942. char FilePath[100]={0};
  12943. char ftpbuf[200];
  12944. int systemresult;
  12945. //DEBUG_INFO("filename=%s\n",filename);
  12946. //DEBUG_INFO("url=%s\n",url);
  12947. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12948. if((access(FilePath,F_OK))!=-1)
  12949. {
  12950. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12951. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12952. system(rmFileCmd);
  12953. }
  12954. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12955. if(fp == NULL)
  12956. {
  12957. DEBUG_INFO("log is NULL\n");
  12958. return FALSE;
  12959. }
  12960. else
  12961. {
  12962. fprintf(fp, "%s\n", url);
  12963. fprintf(fp, "%s\n", filename);
  12964. fclose(fp);
  12965. }
  12966. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12967. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12968. systemresult = system(ftpbuf);
  12969. DEBUG_INFO("systemresult = %d\n",systemresult);
  12970. if(systemresult != 0)
  12971. {
  12972. DEBUG_INFO("http upload error!\n");
  12973. return FALSE;
  12974. }
  12975. return TRUE;
  12976. }
  12977. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12978. {
  12979. struct hostent* server;
  12980. char *IPbuffer;
  12981. char ftpbuf[200];
  12982. int systemresult;
  12983. // To retrieve host information
  12984. server = gethostbyname(location);
  12985. // To convert an Internet network
  12986. // address into ASCII string
  12987. IPbuffer = inet_ntoa(*((struct in_addr*)
  12988. server->h_addr_list[0]));
  12989. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12990. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12991. /* format : ftpput -u username -p passwd IP target source*/
  12992. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12993. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12994. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12995. systemresult = system(ftpbuf);
  12996. DEBUG_INFO("systemresult=%d\n",systemresult);
  12997. if(systemresult != 0)
  12998. {
  12999. DEBUG_INFO("ftpput error!\n");
  13000. return FALSE;
  13001. }
  13002. return TRUE;
  13003. }
  13004. /**
  13005. * Place the contents of the specified file into a memory buffer
  13006. *
  13007. * @param[in] filename The path and name of the file to read
  13008. * @param[out] filebuffer A pointer to the contents in memory
  13009. * @return status 0 success, 1 on failure
  13010. */
  13011. int get_file_contents(const char* filename, char** outbuffer) {
  13012. FILE* file = NULL;
  13013. long filesize;
  13014. const int blocksize = 1;
  13015. size_t readsize;
  13016. char* filebuffer;
  13017. // Open the file
  13018. file = fopen(filename, "r");
  13019. if (NULL == file)
  13020. {
  13021. printf("'%s' not opened\n", filename);
  13022. exit(EXIT_FAILURE);
  13023. }
  13024. // Determine the file size
  13025. fseek(file, 0, SEEK_END);
  13026. filesize = ftell(file);
  13027. rewind (file);
  13028. // Allocate memory for the file contents
  13029. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13030. *outbuffer = filebuffer;
  13031. if (filebuffer == NULL)
  13032. {
  13033. fputs ("malloc out-of-memory", stderr);
  13034. exit(EXIT_FAILURE);
  13035. }
  13036. // Read in the file
  13037. readsize = fread(filebuffer, blocksize, filesize, file);
  13038. if (readsize != filesize)
  13039. {
  13040. fputs ("didn't read file completely",stderr);
  13041. exit(EXIT_FAILURE);
  13042. }
  13043. // Clean exit
  13044. fclose(file);
  13045. return EXIT_SUCCESS;
  13046. }
  13047. static int selectSqlCount = 0;
  13048. static int callback(void *data, int argc, char **argv, char **azColName){
  13049. int i;
  13050. //printf("%s: ", (const char*)data);
  13051. selectSqlCount = argc;
  13052. for(i = 0; i<argc; i++){
  13053. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13054. }
  13055. //printf("\n");
  13056. return 0;
  13057. }
  13058. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13059. //int i;
  13060. //printf("%s:\n", (const char*)data);
  13061. localversion = argv[5] ? atoi(argv[5]) : 0;
  13062. //printf("localversion=%d\n", localversion);
  13063. return 0;
  13064. }
  13065. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13066. //int i;
  13067. //printf("%s:\n", (const char*)data);
  13068. //idTag
  13069. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13070. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13071. //parentIdTag
  13072. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13073. //expir_date
  13074. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13075. //status
  13076. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13077. //version
  13078. idTagQuery.listVersionInt = atoi(argv[5]);
  13079. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13080. return 0;
  13081. }
  13082. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13083. {
  13084. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13085. // printf("localversion=%d\n", localversion);
  13086. return 0;
  13087. }
  13088. //=========================================
  13089. // Sqlite3 related function
  13090. //=========================================
  13091. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13092. {
  13093. for (int i = 0; i < n_columns; i++)
  13094. {
  13095. DEBUG_INFO("%s\t", col_values[i]);
  13096. }
  13097. DEBUG_INFO("\n");
  13098. return 0;
  13099. }
  13100. void OCPP_getListVerion()
  13101. {
  13102. int rc = 0;
  13103. // const char* data = "Callback function called";
  13104. char sql[100];
  13105. char zErrMsg[100];
  13106. memset(sql, 0, 100);
  13107. memset(zErrMsg, 0, 100);
  13108. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13109. /* Execute SQL statement */
  13110. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13111. if( rc != SQLITE_OK )
  13112. {
  13113. DEBUG_INFO("SQL error: %s", zErrMsg);
  13114. }
  13115. }
  13116. void OCPP_getIdTag(char idTag[])
  13117. {
  13118. int rc = 0;
  13119. // const char* data = "Callback function called";
  13120. char sql[100];
  13121. char zErrMsg[100];
  13122. memset(sql, 0, 100);
  13123. memset(zErrMsg, 0, 100);
  13124. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13125. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13126. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13127. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13128. /* Execute SQL statement */
  13129. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13130. if( rc != SQLITE_OK )
  13131. {
  13132. DEBUG_INFO("SQL error: %s", zErrMsg);
  13133. }
  13134. //return ver;
  13135. }
  13136. void OCPP_get_TableAuthlocalAllData(void)
  13137. {
  13138. int rc = 0;
  13139. char sql[100];
  13140. char zErrMsg[100];
  13141. memset(sql, 0, 100);
  13142. memset(zErrMsg, 0, 100);
  13143. sprintf(sql,"select * from ocpp_auth_local ");
  13144. /* Execute SQL statement */
  13145. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13146. if( rc != SQLITE_OK )
  13147. {
  13148. DEBUG_INFO("SQL error: %s", zErrMsg);
  13149. }
  13150. //return ver;
  13151. }
  13152. int OCPP_cleanLocalList()
  13153. {
  13154. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13155. char *errMsg = 0;
  13156. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13157. if (SQLITE_OK != rc)
  13158. {
  13159. DEBUG_INFO("%s\n",errMsg);
  13160. return FALSE;
  13161. }
  13162. return TRUE;
  13163. }
  13164. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13165. {
  13166. int isSuccess = FALSE;
  13167. int ret = 0;
  13168. //const char* data = "Callback function called";
  13169. char sql[300];
  13170. char zErrMsg[200];
  13171. memset(sql, 0, 300);
  13172. memset(zErrMsg, 0, 200);
  13173. 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);
  13174. //* Execute SQL statement */
  13175. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13176. if( ret != SQLITE_OK )
  13177. {
  13178. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13179. return isSuccess;
  13180. }
  13181. memset(sql, 0, 300);
  13182. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13183. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13184. if( ret != SQLITE_OK )
  13185. {
  13186. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13187. return isSuccess;
  13188. }
  13189. isSuccess = TRUE;
  13190. return isSuccess;
  13191. }
  13192. void OCPP_deleteIdTag(char idTag[])
  13193. {
  13194. //int ver = 0;
  13195. //int isSuccess = FALSE;
  13196. int rc = 0;
  13197. char sql[100];
  13198. char zErrMsg[100];
  13199. memset(sql, 0, 100);
  13200. memset(zErrMsg, 0, 100);
  13201. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13202. //* Execute SQL statement */
  13203. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13204. if( rc != SQLITE_OK )
  13205. {
  13206. DEBUG_INFO("SQL error: %s", zErrMsg);
  13207. }
  13208. }
  13209. int GetOcppServerURL()
  13210. {
  13211. int result = FALSE;
  13212. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13213. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13214. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13215. struct yuarel url;
  13216. char urlStr[512];
  13217. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13218. {
  13219. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13220. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13221. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13222. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13223. if(yuarel_parse(&url, urlStr) != -1)
  13224. {
  13225. sprintf(OcppProtocol, "%s", url.scheme);
  13226. sprintf(OcppHost, "%s", url.host);
  13227. if(url.path == NULL)
  13228. OcppTempPath[0] = '\0';
  13229. else
  13230. sprintf(OcppTempPath, "%s", url.path);
  13231. if(url.port == 0)
  13232. {
  13233. if(strcmp(OcppProtocol, "wss") == 0)
  13234. OcppPort = 443;
  13235. else
  13236. OcppPort = 80;
  13237. }
  13238. else
  13239. OcppPort = url.port;
  13240. result = TRUE;
  13241. }
  13242. }
  13243. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13244. {
  13245. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13246. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13247. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13248. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13249. if(yuarel_parse(&url, urlStr) != -1)
  13250. {
  13251. sprintf(OcppProtocol, "%s", url.scheme);
  13252. sprintf(OcppHost, "%s", url.host);
  13253. if(url.path == NULL)
  13254. OcppTempPath[0] = '\0';
  13255. else
  13256. sprintf(OcppTempPath, "%s", url.path);
  13257. if(url.port == 0)
  13258. {
  13259. if(strcmp(OcppProtocol, "wss") == 0)
  13260. OcppPort = 443;
  13261. else
  13262. OcppPort = 80;
  13263. }
  13264. else
  13265. OcppPort = url.port;
  13266. result = TRUE;
  13267. }
  13268. }
  13269. else
  13270. {
  13271. strcpy(OcppHost,"");
  13272. }
  13273. return result;
  13274. }
  13275. int GetOcppPath()
  13276. {
  13277. int result = FALSE;
  13278. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13279. {
  13280. if(OcppTempPath == NULL)
  13281. {
  13282. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13283. }
  13284. else
  13285. {
  13286. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13287. }
  13288. result = TRUE;
  13289. goto End;
  13290. }
  13291. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13292. {
  13293. if(OcppTempPath == NULL)
  13294. {
  13295. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13296. }
  13297. else
  13298. {
  13299. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13300. }
  13301. result = TRUE;
  13302. goto End;
  13303. }
  13304. else
  13305. {
  13306. strcpy(OcppPath,"");
  13307. }
  13308. End:
  13309. return result;
  13310. }
  13311. int GetOcppPort()
  13312. {
  13313. return OcppPort;
  13314. }
  13315. int GetOcppConnStatus(void)
  13316. {
  13317. return ShmOCPP16Data->OcppConnStatus;
  13318. }
  13319. void SetOcppConnStatus(uint8_t status)
  13320. {
  13321. ShmOCPP16Data->OcppConnStatus = status;
  13322. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13323. }
  13324. int GetHeartBeatWithNOResponse(void)
  13325. {
  13326. return HeartBeatWithNOResponse;
  13327. }
  13328. void SetHeartBeatWithNOResponse(void)
  13329. {
  13330. HeartBeatWithNOResponse = 0;
  13331. }
  13332. void GetStartTransactionIdTag(int gun_index)
  13333. {
  13334. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13335. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13336. }
  13337. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13338. {
  13339. char ch;
  13340. FILE *fptr1;
  13341. int temptransactionId;
  13342. char str[100]={0};
  13343. temptransactionId = 0;
  13344. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13345. {
  13346. DEBUG_INFO("IdTag is empty.\n");
  13347. return temptransactionId;
  13348. }
  13349. /*------ Read the file ----------------*/
  13350. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13351. if (!fptr1)
  13352. {
  13353. DEBUG_INFO("QueueTransactionId file open error.\n");
  13354. //printf(" File not found or unable to open the input file!!\n");
  13355. return temptransactionId;
  13356. }
  13357. ch=fgetc(fptr1);
  13358. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13359. rewind(fptr1);
  13360. if(ch!=EOF)
  13361. {
  13362. // printf("%c",ch);
  13363. while (fgets(str, 100, fptr1) != NULL)
  13364. {
  13365. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13366. if(str[0]=='\0')
  13367. {
  13368. break;
  13369. }
  13370. char *revbuf[8] = {0}; // Variable store string split
  13371. int num = 0;// Quantity after string split
  13372. DEBUG_INFO("Transaction queue data= %s\n", str);
  13373. splitstring(str,",",revbuf,&num); // String split
  13374. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13375. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13376. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13377. DEBUG_INFO("------------------------------\n");
  13378. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13379. {
  13380. if(isStopTransaction)
  13381. {
  13382. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13383. {
  13384. temptransactionId = atoi(revbuf[2]);
  13385. break;
  13386. }
  13387. }
  13388. else
  13389. {
  13390. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13391. {
  13392. temptransactionId = atoi(revbuf[2]);
  13393. break;
  13394. }
  13395. }
  13396. }
  13397. }
  13398. }
  13399. else
  13400. DEBUG_INFO("EOF\n");
  13401. fclose(fptr1);
  13402. /*------- End of reading ---------------*/
  13403. return temptransactionId;
  13404. }
  13405. void SetTransactionIdZero(int transactionId)
  13406. {
  13407. char ch;
  13408. FILE *fptr1, *fptr2;
  13409. int temptransactionId = 0;
  13410. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13411. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13412. if (!fptr1)
  13413. {
  13414. //printf(" File not found or unable to open the input file!!\n");
  13415. return ;
  13416. }
  13417. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13418. if (!fptr2)
  13419. {
  13420. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13421. fclose(fptr1);
  13422. return ;
  13423. }
  13424. ch=fgetc(fptr1);
  13425. rewind(fptr1);
  13426. if(ch!=EOF)
  13427. {
  13428. // copy all contents to the temporary file except the specific line
  13429. while (fgets(str, 100, fptr1) != NULL)
  13430. {
  13431. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13432. if(str[0]=='\0')
  13433. {
  13434. break;
  13435. }
  13436. char *revbuf[8] = {0};
  13437. int num = 0;
  13438. strcpy(strtemp, str);
  13439. splitstring(str,",",revbuf,&num);
  13440. if(revbuf[2][0] != '\0')
  13441. {
  13442. temptransactionId = atoi(revbuf[2]);
  13443. if(transactionId != temptransactionId)
  13444. {
  13445. fprintf(fptr2, "%s\n", strtemp);
  13446. }
  13447. }
  13448. }
  13449. }
  13450. fclose(fptr1);
  13451. fclose(fptr2);
  13452. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13453. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13454. /*------ Read the file ----------------*/
  13455. }
  13456. int InternetDisconnect(void)
  13457. {
  13458. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13459. }
  13460. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13461. void storeTempStopTransaction(int gun_index)
  13462. {
  13463. char guid[37]={0};
  13464. int tempIndex = 0;
  13465. char TempStopTransaction[256];
  13466. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13467. DEBUG_INFO("storeTempStopTransaction...\n");
  13468. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13469. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13470. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13471. if(gunType[gun_index] == 'J')
  13472. {
  13473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13474. {
  13475. tempIndex = ((gun_index==2) ? 1: 0);
  13476. }
  13477. else
  13478. {
  13479. tempIndex = gun_index;
  13480. }
  13481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13482. {
  13483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13484. {
  13485. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13486. }
  13487. }// END OF CHAdeMO_QUANTITY
  13488. }
  13489. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13490. {
  13491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13492. {
  13493. tempIndex = ((gun_index==2) ? 1: 0);
  13494. }
  13495. else
  13496. {
  13497. tempIndex = gun_index;
  13498. }
  13499. for (int index = 0; index < CCS_QUANTITY; index++)
  13500. {
  13501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13502. {
  13503. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13504. }
  13505. }// END OF CCS_QUANTITY
  13506. }
  13507. else if(gunType[gun_index] == 'G')
  13508. {
  13509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13510. {
  13511. tempIndex = ((gun_index==2) ? 1: 0);
  13512. }
  13513. else
  13514. {
  13515. tempIndex = gun_index;
  13516. }
  13517. for (int index = 0; index < GB_QUANTITY; index++)
  13518. {
  13519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13520. {
  13521. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13522. }
  13523. }// END OF GB_QUANTITY
  13524. }
  13525. else if(gunType[gun_index] == 'O')
  13526. {
  13527. tempIndex = gun_index;
  13528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13529. {
  13530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13531. {
  13532. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13533. }
  13534. }
  13535. }
  13536. else
  13537. {
  13538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13539. {
  13540. tempIndex = 2;
  13541. }
  13542. else
  13543. {
  13544. tempIndex = gun_index;
  13545. }
  13546. for (int index = 0; index < AC_QUANTITY; index++)
  13547. {
  13548. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13549. {
  13550. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13551. }
  13552. }// END OF AC_QUANTITY
  13553. }
  13554. //Stop Transaction Time
  13555. struct timeval tmnow;
  13556. struct tm *tm;
  13557. char buf[28];//, usec_buf[6];
  13558. gettimeofday(&tmnow, NULL);
  13559. time_t t;
  13560. t = time(NULL);
  13561. /*UTC time and date*/
  13562. tm = gmtime(&t);
  13563. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13565. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13567. random_uuid(guid);
  13568. /***********************************transactionData******************************************************/
  13569. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13571. //=================================
  13572. //1. Transaction_Begin
  13573. //=================================
  13574. //============================== Energy.Active.Import.Interval ===========================================
  13575. //idx_sample=0;
  13576. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13579. 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*/]);
  13580. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13581. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13582. {
  13583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13584. }
  13585. else
  13586. {
  13587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13588. }
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13591. //=================================
  13592. //2. Transaction_End
  13593. //=================================
  13594. //2.1====================================== Current.Import L1 ==============================================
  13595. //idx_sample=1;
  13596. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13597. if(gunType[gun_index] == 'J')
  13598. {
  13599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13600. {
  13601. tempIndex = ((gun_index==2) ? 1: 0);
  13602. }
  13603. else
  13604. {
  13605. tempIndex = gun_index;
  13606. }
  13607. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13608. {
  13609. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13610. {
  13611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13612. }
  13613. }// End of for CHAdeMO_QUANTITY
  13614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13615. }
  13616. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13617. {
  13618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13619. {
  13620. tempIndex = ((gun_index==2) ? 1: 0);
  13621. }
  13622. else
  13623. {
  13624. tempIndex = gun_index;
  13625. }
  13626. for (int index = 0; index < CCS_QUANTITY; index++)
  13627. {
  13628. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13629. {
  13630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13631. }
  13632. }// End of for CCS_QUANTITY
  13633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13634. }
  13635. else if(gunType[gun_index] == 'G')
  13636. {
  13637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13638. {
  13639. tempIndex = ((gun_index==2) ? 1: 0);
  13640. }
  13641. else
  13642. {
  13643. tempIndex = gun_index;
  13644. }
  13645. for (int index = 0; index < GB_QUANTITY; index++)
  13646. {
  13647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13648. {
  13649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13650. }
  13651. }// End of for GB_QUANTITY
  13652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13653. }
  13654. else if(gunType[gun_index] == 'O')
  13655. {
  13656. tempIndex = gun_index;
  13657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13658. {
  13659. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13660. {
  13661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13662. }
  13663. }
  13664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13665. }
  13666. else
  13667. {
  13668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13669. {
  13670. tempIndex = 2;
  13671. }
  13672. else
  13673. {
  13674. tempIndex = gun_index;
  13675. }
  13676. for (int index = 0; index < AC_QUANTITY; index++)
  13677. {
  13678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13679. {
  13680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13681. }
  13682. }// End of for AC_QUANTITY
  13683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13684. }
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13688. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13691. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13692. //idx_sample=2;
  13693. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13694. if(gunType[gun_index] == 'J')
  13695. {
  13696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13697. {
  13698. tempIndex = ((gun_index==2) ? 1: 0);
  13699. }
  13700. else
  13701. {
  13702. tempIndex = gun_index;
  13703. }
  13704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13705. {
  13706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13707. {
  13708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13709. }
  13710. }// END OF CHAdeMO_QUANTITY
  13711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13712. }
  13713. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13714. {
  13715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13716. {
  13717. tempIndex = ((gun_index==2) ? 1: 0);
  13718. }
  13719. else
  13720. {
  13721. tempIndex = gun_index;
  13722. }
  13723. for (int index = 0; index < CCS_QUANTITY; index++)
  13724. {
  13725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13726. {
  13727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13728. }
  13729. }// END OF CCS_QUANTITY
  13730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13731. }
  13732. else if(gunType[gun_index] == 'G')
  13733. {
  13734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13735. {
  13736. tempIndex = ((gun_index==2) ? 1: 0);
  13737. }
  13738. else
  13739. {
  13740. tempIndex = gun_index;
  13741. }
  13742. for (int index = 0; index < GB_QUANTITY; index++)
  13743. {
  13744. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13745. {
  13746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13747. }
  13748. }// END OF GB_QUANTITY
  13749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13750. }
  13751. else if(gunType[gun_index] == 'O')
  13752. {
  13753. tempIndex = gun_index;
  13754. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13755. {
  13756. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13757. {
  13758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13759. }
  13760. }
  13761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13762. }
  13763. else
  13764. {
  13765. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13766. {
  13767. tempIndex = 2;
  13768. }
  13769. else
  13770. {
  13771. tempIndex = gun_index;
  13772. }
  13773. for (int index = 0; index < AC_QUANTITY; index++)
  13774. {
  13775. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13776. {
  13777. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13778. }
  13779. }// END OF AC_QUANTITY
  13780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13781. }
  13782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13785. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13788. //2.3====================================== Power.Active.Import =========================================
  13789. //idx_sample=3;
  13790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13791. if(gunType[gun_index] == 'J')
  13792. {
  13793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13794. {
  13795. tempIndex = ((gun_index==2) ? 1: 0);
  13796. }
  13797. else
  13798. {
  13799. tempIndex = gun_index;
  13800. }
  13801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13802. {
  13803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13804. {
  13805. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13806. }
  13807. } // End for CHAdeMO_QUANTITY
  13808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13809. }
  13810. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13811. {
  13812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13813. {
  13814. tempIndex = ((gun_index==2) ? 1: 0);
  13815. }
  13816. else
  13817. {
  13818. tempIndex = gun_index;
  13819. }
  13820. for (int index = 0; index < CCS_QUANTITY; index++)
  13821. {
  13822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13823. {
  13824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13825. }
  13826. } // END for CCS_QUANTITY
  13827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13828. }
  13829. else if(gunType[gun_index] == 'G')
  13830. {
  13831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13832. {
  13833. tempIndex = ((gun_index==2) ? 1: 0);
  13834. }
  13835. else
  13836. {
  13837. tempIndex = gun_index;
  13838. }
  13839. for (int index = 0; index < GB_QUANTITY; index++)
  13840. {
  13841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13842. {
  13843. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13844. }
  13845. }// END for GB_QUANTITY
  13846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13847. }
  13848. else if(gunType[gun_index] == 'O')
  13849. {
  13850. tempIndex = gun_index;
  13851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13852. {
  13853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13854. {
  13855. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13856. }
  13857. }
  13858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13859. }
  13860. else
  13861. {
  13862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13863. {
  13864. tempIndex = 2;
  13865. }
  13866. else
  13867. {
  13868. tempIndex = gun_index;
  13869. }
  13870. for (int index = 0; index < AC_QUANTITY; index++)
  13871. {
  13872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13873. {
  13874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13875. }
  13876. } // END for AC_QUANTITY
  13877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13878. }
  13879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13882. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13885. //2.4====================================== Voltage L1 ====================================================
  13886. //idx_sample=4;
  13887. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13888. if(gunType[gun_index] == 'J')
  13889. {
  13890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13891. {
  13892. tempIndex = ((gun_index==2) ? 1: 0);
  13893. }
  13894. else
  13895. {
  13896. tempIndex = gun_index;
  13897. }
  13898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13899. {
  13900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13901. {
  13902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13903. }
  13904. } // END OF FOR CHAdeMO_QUANTITY
  13905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13906. }
  13907. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13908. {
  13909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13910. {
  13911. tempIndex = ((gun_index==2) ? 1: 0);
  13912. }
  13913. else
  13914. {
  13915. tempIndex = gun_index;
  13916. }
  13917. for (int index = 0; index < CCS_QUANTITY; index++)
  13918. {
  13919. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13920. {
  13921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13922. }
  13923. } // END OF FOR CCS_QUANTITY
  13924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13925. }
  13926. else if(gunType[gun_index] == 'G')
  13927. {
  13928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13929. {
  13930. tempIndex = ((gun_index==2) ? 1: 0);
  13931. }
  13932. else
  13933. {
  13934. tempIndex = gun_index;
  13935. }
  13936. for (int index = 0; index < GB_QUANTITY; index++)
  13937. {
  13938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13939. {
  13940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13941. }
  13942. } // END OF FOR GB_QUANTITY
  13943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13944. }
  13945. else if(gunType[gun_index] == 'O')
  13946. {
  13947. tempIndex = gun_index;
  13948. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13949. {
  13950. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13951. {
  13952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13953. }
  13954. }
  13955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13956. }
  13957. else
  13958. {
  13959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13960. {
  13961. tempIndex = 2;
  13962. }
  13963. else
  13964. {
  13965. tempIndex = gun_index;
  13966. }
  13967. for (int index = 0; index < AC_QUANTITY; index++)
  13968. {
  13969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13970. {
  13971. 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
  13972. }
  13973. } // END OF FOR AC_QUANTITY
  13974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13975. }
  13976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13979. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13982. //2.5============================================== SoC =========================================================
  13983. //idx_sample=5;
  13984. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13985. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13986. {
  13987. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13988. {
  13989. tempIndex = ((gun_index==2) ? 1: 0);
  13990. }
  13991. else
  13992. {
  13993. tempIndex = gun_index;
  13994. }
  13995. if(gunType[gun_index] == 'J')
  13996. {
  13997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13998. {
  13999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14000. {
  14001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14002. }
  14003. }
  14004. }
  14005. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14006. {
  14007. for (int index = 0; index < CCS_QUANTITY; index++)
  14008. {
  14009. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14010. {
  14011. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14012. }
  14013. }
  14014. }
  14015. else if(gunType[gun_index] == 'G')
  14016. {
  14017. for (int index = 0; index < GB_QUANTITY; index++)
  14018. {
  14019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14020. {
  14021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14022. }
  14023. }
  14024. }
  14025. else if(gunType[gun_index] == 'O')
  14026. {
  14027. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14028. {
  14029. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14030. {
  14031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14032. }
  14033. }
  14034. }
  14035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  14040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14041. } // END FOR DC CASE
  14042. //2.6====================================== Current.Import L2 ==============================================
  14043. // idx_sample=6;
  14044. // AC 3 phase L2 current
  14045. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14046. {
  14047. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14048. {
  14049. tempIndex = 2;
  14050. }
  14051. else
  14052. {
  14053. tempIndex = gun_index;
  14054. }
  14055. for (int index = 0; index < AC_QUANTITY; index++)
  14056. {
  14057. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14058. {
  14059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14060. }
  14061. }// End of for AC_QUANTITY
  14062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14063. }
  14064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14069. //2.7====================================== Current.Import L3 ==============================================
  14070. // idx_sample=7;
  14071. // AC 3 phase L3 current
  14072. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14073. {
  14074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14075. {
  14076. tempIndex = 2;
  14077. }
  14078. else
  14079. {
  14080. tempIndex = gun_index;
  14081. }
  14082. for (int index = 0; index < AC_QUANTITY; index++)
  14083. {
  14084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14085. {
  14086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14087. }
  14088. }// End of for AC_QUANTITY
  14089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14090. }
  14091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14096. //2.9====================================== Voltage L2 ====================================================
  14097. //idx_sample=8;
  14098. // AC 3 phase L2 volatge
  14099. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14100. {
  14101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14102. {
  14103. tempIndex = 2;
  14104. }
  14105. else
  14106. {
  14107. tempIndex = gun_index;
  14108. }
  14109. for (int index = 0; index < AC_QUANTITY; index++)
  14110. {
  14111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14112. {
  14113. 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
  14114. }
  14115. } // END OF FOR AC_QUANTITY
  14116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14117. }
  14118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14123. //2.10====================================== Voltage L3 ====================================================
  14124. //idx_sample=9;
  14125. // AC 3 phase L3 volatge
  14126. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14127. {
  14128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14129. {
  14130. tempIndex = 2;
  14131. }
  14132. else
  14133. {
  14134. tempIndex = gun_index;
  14135. }
  14136. for (int index = 0; index < AC_QUANTITY; index++)
  14137. {
  14138. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14139. {
  14140. 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
  14141. }
  14142. } // END OF FOR AC_QUANTITY
  14143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14144. }
  14145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14150. //======================================== Message create ==============================================
  14151. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14152. {
  14153. 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\"}]}]}]"
  14154. ,gun_index+1
  14155. ,MESSAGE_TYPE_CALL
  14156. ,guid
  14157. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14158. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14159. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14160. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14161. ,"PowerLoss"
  14162. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14163. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14164. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14165. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14166. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14167. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14168. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14169. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14170. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14171. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14172. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14173. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14174. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14175. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14176. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14177. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14178. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14179. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14180. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14181. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14182. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14184. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14185. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14186. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14189. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14190. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14191. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14192. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14193. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14194. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14195. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14196. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14197. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14198. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  14199. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  14200. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  14201. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  14202. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  14203. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  14204. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  14205. );
  14206. }
  14207. else
  14208. {
  14209. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  14210. {
  14211. 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\"}]}]}]"
  14212. ,gun_index+1
  14213. ,MESSAGE_TYPE_CALL
  14214. ,guid
  14215. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14216. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14217. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14218. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14219. ,"PowerLoss"
  14220. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14221. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14222. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14223. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14224. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14225. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14226. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14227. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14228. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14229. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14230. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14231. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14232. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14233. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14234. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14235. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14236. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14237. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14238. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14239. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14240. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14242. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14243. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14256. );
  14257. }
  14258. else
  14259. {
  14260. 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\"}]}]}]"
  14261. ,gun_index+1
  14262. ,MESSAGE_TYPE_CALL
  14263. ,guid
  14264. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14265. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14266. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14268. ,"PowerLoss"
  14269. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14286. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14290. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14291. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14292. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14293. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14294. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14295. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14296. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14297. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14298. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14299. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14300. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14301. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14302. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14303. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14304. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14305. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14306. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14307. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14308. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14309. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14310. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14311. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14312. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14313. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14314. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14315. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14316. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14317. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14318. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14319. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14320. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14321. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14322. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14323. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14324. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14325. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14326. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14327. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14328. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14329. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14330. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14331. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14332. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14333. );
  14334. }
  14335. }
  14336. // Check File "TempStopTransaction" Exist
  14337. if((access(TempStopTransaction,F_OK))!=-1)
  14338. {
  14339. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14340. fclose(fopen(TempStopTransaction, "w"));
  14341. }
  14342. else
  14343. {
  14344. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14345. FILE *log = fopen(TempStopTransaction, "w+");
  14346. if(log == NULL)
  14347. {
  14348. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14349. return ;
  14350. }
  14351. else
  14352. {
  14353. fclose(log);
  14354. }
  14355. }
  14356. //Add TempStopTransaction | Update TempStopTransaction
  14357. // open file for writing
  14358. FILE *outfile;
  14359. outfile = fopen (TempStopTransaction, "a");
  14360. //DEBUG_INFO("data = %s\n", queuedata);
  14361. fputs(queuedata, outfile);
  14362. fputs("\n", outfile);
  14363. fclose (outfile);
  14364. }
  14365. void checkTempStopTransaction(int gun_index)
  14366. {
  14367. FILE *fptr1;
  14368. char ch;
  14369. char str[QUEUE_MESSAGE_LENGTH]={0};
  14370. char guid[37]={0};
  14371. char tempdata[65]={0};
  14372. char connectorStr[2]={0};
  14373. char TempStopTransaction[256];
  14374. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14375. fptr1 = fopen(TempStopTransaction, "r");
  14376. //TempStopTransaction格式: 槍號,StopTransaction封包
  14377. if (!fptr1)
  14378. {
  14379. //printf(" File not found or unable to open the input file!!\n");
  14380. return ;
  14381. }
  14382. ch=fgetc(fptr1);
  14383. //printf(" Now the content of the file %s is : \n",fname);
  14384. rewind(fptr1);
  14385. if(ch!=EOF)
  14386. {
  14387. // copy all contents to the temporary file except the specific line
  14388. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14389. {
  14390. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14391. if(str[0]=='\0')
  14392. {
  14393. break;
  14394. }
  14395. //TempStopTransaction格式: 槍號,StopTransaction封包
  14396. strncpy(connectorStr, str, 1);
  14397. if(atoi(connectorStr) != (gun_index+1))
  14398. {
  14399. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14400. fclose(fptr1);
  14401. return ;
  14402. }
  14403. //random_uuid(guid);
  14404. strncpy(guid, str+6, 36); //copy guid
  14405. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14406. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14407. {
  14408. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14409. }
  14410. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14411. memset(str,0,ARRAY_SIZE(str));
  14412. }
  14413. }
  14414. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14415. fclose(fptr1);
  14416. remove(TempStopTransaction); // remove the original file
  14417. }
  14418. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14419. {
  14420. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14421. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14422. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14423. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14424. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14425. }
  14426. int GetWebSocketPingInterval(void)
  14427. {
  14428. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14429. }
  14430. int GetServerSign(void)
  14431. {
  14432. return server_sign;
  14433. }
  14434. uint8_t GetOcppSecurityProfile()
  14435. {
  14436. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14437. }
  14438. void GetOcppChargerBoxId(uint8_t *data)
  14439. {
  14440. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14441. }
  14442. void GetOcppSecurityPassword(uint8_t *data)
  14443. {
  14444. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14445. }
  14446. void SetServerSign(int value)
  14447. {
  14448. server_sign = value;
  14449. }
  14450. int GetBootNotificationInterval(void)
  14451. {
  14452. return BootNotificationInterval;
  14453. }
  14454. int GetInternetConn(void)
  14455. {
  14456. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14457. }
  14458. void InitialSystemValue(void)
  14459. {
  14460. int connectorIndex = 0;
  14461. //int valueASCII = 0;
  14462. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14463. gunTotalNumber=0;
  14464. SystemInitial = 0;
  14465. localversion=0;
  14466. BootNotificationInterval = 0;
  14467. authorizeRetryTimes = 0;
  14468. GunStatusInterval = 10;
  14469. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14470. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14471. //Hear Beat
  14472. HeartBeatWithNOResponse = 0;
  14473. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14474. FirstHeartBeat = 0;
  14475. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14476. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14477. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14478. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14479. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14480. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14481. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14482. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14483. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14484. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14485. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14486. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14487. memset(gunType, 0, ARRAY_SIZE(gunType));
  14488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14489. {
  14490. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14491. {
  14492. // DO series
  14493. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14494. {
  14495. SystemInitial = SystemInitial + 1;
  14496. gunTotalNumber = gunTotalNumber + 1;
  14497. gunType[connectorIndex] = 'O';
  14498. connectorIndex = connectorIndex + 1;
  14499. }
  14500. }
  14501. else
  14502. {
  14503. // DM, DW, DS series
  14504. //check connector / socket type (index: 8, 9, 10)
  14505. for(int index=7; index <10 ; index++)
  14506. {
  14507. if(index != 8)
  14508. {
  14509. // DC Connector
  14510. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14511. {
  14512. SystemInitial = SystemInitial + 1;
  14513. gunTotalNumber = gunTotalNumber + 1;
  14514. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14515. connectorIndex = connectorIndex + 1;
  14516. }
  14517. }
  14518. else
  14519. {
  14520. // AC Connector
  14521. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14522. {
  14523. SystemInitial = SystemInitial + 1;
  14524. gunTotalNumber = gunTotalNumber + 1;
  14525. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14526. connectorIndex = connectorIndex + 1;
  14527. }
  14528. }
  14529. }
  14530. }
  14531. //DEBUG_INFO("DC ...\n");
  14532. }
  14533. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14534. {
  14535. //check connector / socket type (index: 8, 9, 10)
  14536. for(int index=7; index <10 ; index++)
  14537. {
  14538. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14539. {
  14540. SystemInitial = SystemInitial + 1;
  14541. gunTotalNumber = gunTotalNumber + 1;
  14542. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14543. connectorIndex = connectorIndex + 1;
  14544. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14545. }
  14546. }
  14547. }
  14548. //Status && ConnectorPlugIn Setting
  14549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14550. {
  14551. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14552. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14553. }
  14554. for (int index = 0; index < CCS_QUANTITY; index++)
  14555. {
  14556. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14557. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14558. }
  14559. for (int index = 0; index < GB_QUANTITY; index++)
  14560. {
  14561. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14562. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14563. }
  14564. for (int index = 0; index < AC_QUANTITY; index++)
  14565. {
  14566. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14567. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14568. }
  14569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14570. {
  14571. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14572. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14573. }
  14574. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14575. {
  14576. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14577. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14578. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14579. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14580. }
  14581. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14582. clientTime.Heartbeat=time((time_t*)NULL);
  14583. sleep(1);
  14584. }
  14585. void LWS_Send(char * str)
  14586. {
  14587. //=====================================================
  14588. // Check InternetConn 0: disconnected, 1: connected
  14589. //====================================================
  14590. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14591. {
  14592. DEBUG_INFO("offline now !!!\n");
  14593. return;
  14594. }
  14595. pthread_mutex_lock(&lock_send);
  14596. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14597. sprintf((char *)SendBuffer, "%s", str);
  14598. SendBufLen = strlen(str);
  14599. pthread_mutex_unlock(&lock_send);
  14600. lws_callback_on_writable(wsi_client);
  14601. //lws_service(context, 0);
  14602. //sleep(1);
  14603. }
  14604. void LWS_SendNow(char * str)
  14605. {
  14606. //=====================================================
  14607. // Check InternetConn 0: disconnected, 1: connected
  14608. //====================================================
  14609. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14610. {
  14611. DEBUG_INFO("offline now !!!\n");
  14612. return;
  14613. }
  14614. pthread_mutex_lock(&lock_send);
  14615. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14616. sprintf((char *)SendBuffer, "%s", str);
  14617. SendBufLen = strlen(str);
  14618. pthread_mutex_unlock(&lock_send);
  14619. lws_callback_on_writable(wsi_client);
  14620. lws_service(context, 0);
  14621. //sleep(1);
  14622. }