MessageHandler.c 669 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228
  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 44
  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[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_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 ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  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[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq :1; //bit 0,
  124. unsigned char StatusNotificationConf :1; //bit 0,
  125. unsigned char :6; //bit 2~7
  126. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  127. }CpinitiateMsg;
  128. CpinitiateMsg cpinitateMsg;
  129. //GetConfiguration Array
  130. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  133. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  134. #if 0
  135. static char *ChargePointErrorCodeStr[] = {
  136. MACROSTR(ConnectorLockFailure),
  137. MACROSTR(EVCommunicationError),
  138. MACROSTR(GroundFailure),
  139. MACROSTR(HighTemperature),
  140. MACROSTR(InternalError),
  141. MACROSTR(LocalListConflict),
  142. MACROSTR(NoError),
  143. MACROSTR(OtherError),
  144. MACROSTR(OverCurrentFailure),
  145. MACROSTR(OverVoltage),
  146. MACROSTR(PowerMeterFailure),
  147. MACROSTR(PowerSwitchFailure),
  148. MACROSTR(ReaderFailure),
  149. MACROSTR(ResetFailure),
  150. MACROSTR(UnderVoltage),
  151. MACROSTR(WeakSignal)
  152. };
  153. #endif
  154. static char * ChargePointStatusStr[] = {
  155. MACROSTR(Available),
  156. MACROSTR(Preparing),
  157. MACROSTR(Charging),
  158. MACROSTR(SuspendedEVSE),
  159. MACROSTR(SuspendedEV),
  160. MACROSTR(Finishing),
  161. MACROSTR(Reserved),
  162. MACROSTR(Unavailable),
  163. MACROSTR(Faulted)
  164. };
  165. static char *RegistrationStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Pending),
  168. MACROSTR(Rejected)
  169. };
  170. static char *AvailabilityTypeStr[] = {
  171. MACROSTR(Inoperative),
  172. MACROSTR(Operative)
  173. };
  174. static char *AvailabilityStatusStr[] = {
  175. MACROSTR(Accepted),
  176. MACROSTR(Rejected),
  177. MACROSTR(Scheduled)
  178. };
  179. static char *ConfigurationStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(RebootRequired),
  183. MACROSTR(NotSupported)
  184. };
  185. static char *ClearCacheStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected)
  188. };
  189. static char *ChargingProfilePurposeTypeStr[] = {
  190. MACROSTR(ChargePointMaxProfile),
  191. MACROSTR(TxDefaultProfile),
  192. MACROSTR(TxProfile)
  193. };
  194. static char *ChargingProfileStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupported)
  198. };
  199. static char *ClearChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Unknown)
  202. };
  203. static char *GetCompositeScheduleStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Rejected)
  206. };
  207. static char *UpdateTypeStr[] = {
  208. MACROSTR(Differential),
  209. MACROSTR(Full)
  210. };
  211. static char *UpdateStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Failed),
  214. MACROSTR(NotSupported),
  215. MACROSTR(VersionMismatch)
  216. };
  217. static char *RemoteStartStopStatusStr[] = {
  218. MACROSTR(Accepted),
  219. MACROSTR(Rejected)
  220. };
  221. static char *ReservationStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Faulted),
  224. MACROSTR(Occupied),
  225. MACROSTR(Rejected),
  226. MACROSTR(Unavailable)
  227. };
  228. static char *ResetTypeStr[] = {
  229. MACROSTR(Hard),
  230. MACROSTR(Soft)
  231. };
  232. static char *ResetStatusStr[] = {
  233. MACROSTR(Accepted),
  234. MACROSTR(Rejected)
  235. };
  236. static char * DiagnosticsStatusStr[] = {
  237. MACROSTR(Idle),
  238. MACROSTR(Uploaded),
  239. MACROSTR(UploadFailed),
  240. MACROSTR(Uploading)
  241. };
  242. static char * FirmwareStatusStr[] = {
  243. MACROSTR(Downloaded),
  244. MACROSTR(DownloadFailed),
  245. MACROSTR(Downloading),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed)
  250. };
  251. static char * MessageTriggerStr[] = {
  252. MACROSTR(BootNotification),
  253. MACROSTR(DiagnosticsStatusNotification),
  254. MACROSTR(FirmwareStatusNotification),
  255. MACROSTR(Heartbeat),
  256. MACROSTR(MeterValues),
  257. MACROSTR(StatusNotification)
  258. };
  259. static char * TriggerMessageStatusStr[] = {
  260. MACROSTR(Accepted),
  261. MACROSTR(Rejected),
  262. MACROSTR(NotImplemented)
  263. };
  264. static char * UnlockStatusStr[] = {
  265. MACROSTR(Unlocked),
  266. MACROSTR(UnlockFailed),
  267. MACROSTR(NotSupported)
  268. };
  269. #if 0
  270. static char * StopTransactionReasonStr[] = {
  271. MACROSTR(EmergencyStop),
  272. MACROSTR(EVDisconnected),
  273. MACROSTR(HardReset),
  274. MACROSTR(Local),
  275. MACROSTR(Other),
  276. MACROSTR(PowerLoss),
  277. MACROSTR(Reboot),
  278. MACROSTR(Remote),
  279. MACROSTR(SoftReset),
  280. MACROSTR(UnlockCommand),
  281. MACROSTR(DeAuthorized)
  282. };
  283. #endif
  284. static char * CancelReservationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected)
  287. };
  288. static char * ReadingContextStr[] = {
  289. MACROSTR(Interruption.Begin),
  290. MACROSTR(Interruption.End),
  291. MACROSTR(Other),
  292. MACROSTR(Sample.Clock),
  293. MACROSTR(Sample.Periodic),
  294. MACROSTR(Transaction.Begin),
  295. MACROSTR(Transaction.End),
  296. MACROSTR(Trigger)
  297. };
  298. static char * ValueFormatStr[] = {
  299. MACROSTR(Raw),
  300. MACROSTR(SignedData)
  301. };
  302. static char * MeasurandStr[] = {
  303. MACROSTR(Current.Export),
  304. MACROSTR(Current.Import),
  305. MACROSTR(Current.Offered),
  306. MACROSTR(Energy.Active.Export.Register),
  307. MACROSTR(Energy.Active.Import.Register),
  308. MACROSTR(Energy.Reactive.Export.Register),
  309. MACROSTR(Energy.Reactive.Import.Register),
  310. MACROSTR(Energy.Active.Export.Interval),
  311. MACROSTR(Energy.Active.Import.Interval),
  312. MACROSTR(Energy.Reactive.Export.Interval),
  313. MACROSTR(Energy.Reactive.Import.Interval),
  314. MACROSTR(Frequency),
  315. MACROSTR(Power.Active.Export),
  316. MACROSTR(Power.Active.Import),
  317. MACROSTR(Power.Factor),
  318. MACROSTR(Power.Offered),
  319. MACROSTR(Power.Reactive.ExportMACROSTR),
  320. MACROSTR(Power.Reactive.Import),
  321. MACROSTR(RPM),
  322. MACROSTR(SoC),
  323. MACROSTR(Temperature),
  324. MACROSTR(Voltage)
  325. };
  326. static char * LocationStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char * PhaseStr[] = {
  334. MACROSTR(L1),
  335. MACROSTR(L2),
  336. MACROSTR(L3),
  337. MACROSTR(N),
  338. MACROSTR(L1-N),
  339. MACROSTR(L2-N),
  340. MACROSTR(L3-N),
  341. MACROSTR(L1-L2),
  342. MACROSTR(L2-L3),
  343. MACROSTR(L3-L1)
  344. };
  345. static char * UnitOfMeasureStr[] = {
  346. MACROSTR(Wh),
  347. MACROSTR(kWh),
  348. MACROSTR(varh),
  349. MACROSTR(kvarh),
  350. MACROSTR(W),
  351. MACROSTR(kW),
  352. MACROSTR(VA),
  353. MACROSTR(kVA),
  354. MACROSTR(var),
  355. MACROSTR(kvar),
  356. MACROSTR(A),
  357. MACROSTR(V),
  358. MACROSTR(Celsius),
  359. MACROSTR(Fahrenheit),
  360. MACROSTR(K),
  361. MACROSTR(Percent)
  362. };
  363. //==========================================
  364. // Check time passed since today
  365. //==========================================
  366. long long DiffTimebWithNow(struct timeb ST)
  367. {
  368. //return milli-second
  369. struct timeb ET;
  370. long long StartTime,StopTime;
  371. ftime(&ET);
  372. StartTime=(long long)ST.time;
  373. StopTime=(long long)ET.time;
  374. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  375. }
  376. int getTimePassSinceToday()
  377. {
  378. int result = -1;
  379. time_t t;
  380. struct tm *tmStartToday;
  381. struct timeb tbStartToday;
  382. t=time(NULL);
  383. tmStartToday=localtime(&t);
  384. tmStartToday->tm_hour = 0;
  385. tmStartToday->tm_min = 0;
  386. tmStartToday->tm_sec = 0;
  387. tbStartToday.time = mktime(tmStartToday);
  388. tbStartToday.millitm = 0;
  389. result = DiffTimebWithNow(tbStartToday)/1000;
  390. return result;
  391. }
  392. //==========================================
  393. // GetCompositeSchedule logic related function
  394. //==========================================
  395. int DiffTimebSec(struct timeb ST, struct timeb ET)
  396. {
  397. //return milli-second
  398. unsigned int StartTime,StopTime;
  399. StartTime=(unsigned int)ST.time;
  400. StopTime=(unsigned int)ET.time;
  401. return (StopTime-StartTime);
  402. }
  403. int DiffTimebWithNowSec(struct timeb ST)
  404. {
  405. //return milli-second
  406. struct timeb ET;
  407. unsigned int StartTime,StopTime;
  408. ftime(&ET);
  409. StartTime=(unsigned int)ST.time;
  410. StopTime=(unsigned int)ET.time;
  411. return (StopTime-StartTime);
  412. }
  413. int getStartStop(uint8_t *start, uint8_t *stop)
  414. {
  415. int result = -1;
  416. struct tm tmStart;
  417. struct timeb tbStart;
  418. struct tm tmStop;
  419. struct timeb tbStop;
  420. 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) &&
  421. (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))
  422. {
  423. tmStart.tm_year -= 1900;
  424. tmStart.tm_mon -= 1;
  425. tbStart.time = mktime(&tmStart);
  426. tbStart.millitm = 0;
  427. tmStop.tm_year -= 1900;
  428. tmStop.tm_mon -= 1;
  429. tbStop.time = mktime(&tmStop);
  430. tbStop.millitm = 0;
  431. result = DiffTimebSec(tbStart, tbStop);
  432. }
  433. else
  434. {
  435. DEBUG_WARN("Start or stop date parsing error.\r\n");
  436. }
  437. return result;
  438. }
  439. int getStartSinceToday(uint8_t *stop)
  440. {
  441. int result = -1;
  442. time_t t;
  443. struct tm *tmStartToday;
  444. struct timeb tbStartToday;
  445. struct tm tmStop;
  446. struct timeb tbStop;
  447. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  448. {
  449. t=time(NULL);
  450. tmStartToday=localtime(&t);
  451. tmStartToday->tm_hour = 0;
  452. tmStartToday->tm_min = 0;
  453. tmStartToday->tm_sec = 0;
  454. tbStartToday.time = mktime(tmStartToday);
  455. tmStop.tm_year -= 1900;
  456. tmStop.tm_mon -= 1;
  457. tbStop.time = mktime(&tmStop);
  458. tbStop.millitm = 0;
  459. result = DiffTimebSec(tbStartToday, tbStop);
  460. }
  461. return result;
  462. }
  463. int getStartSinceWeek(uint8_t *stop)
  464. {
  465. int result = -1;
  466. time_t t;
  467. struct tm *tmStartWeek;
  468. struct timeb tbStartWeek;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  472. {
  473. t=time(NULL);
  474. tmStartWeek=localtime(&t);
  475. t-=86400*tmStartWeek->tm_wday;
  476. tmStartWeek=localtime(&t);
  477. tmStartWeek->tm_hour = 0;
  478. tmStartWeek->tm_min = 0;
  479. tmStartWeek->tm_sec = 0;
  480. tbStartWeek.time = mktime(tmStartWeek);
  481. tmStop.tm_year -= 1900;
  482. tmStop.tm_mon -= 1;
  483. tbStop.time = mktime(&tmStop);
  484. tbStop.millitm = 0;
  485. result = DiffTimebSec(tbStartWeek, tbStop);
  486. }
  487. return result;
  488. }
  489. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  490. {
  491. FILE *fp;
  492. char profileFileName[128];
  493. char *line = NULL;
  494. size_t len = 0;
  495. time_t CurrentTime;
  496. struct tm *tmComposite;
  497. struct StructChargingProfile maxProfile;
  498. struct StructChargingProfile defaultTxProfile;
  499. struct StructChargingProfile txProfile;
  500. struct StructChargingSchedulePeriod tmpPeriod;
  501. uint8_t limitMax=0;
  502. uint8_t limitDef=0;
  503. uint8_t limitTx=0;
  504. int compositePeriodIdx = 0;
  505. CurrentTime = time(NULL);
  506. tmComposite=localtime(&CurrentTime);
  507. 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);
  508. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  509. compositeProfile->ChargingSchedule.Duration = durationReq;
  510. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  511. {
  512. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  515. }
  516. compositeProfile->ChargingProfileId = 0;
  517. compositeProfile->StackLevel = 99 ;
  518. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  519. maxProfile.ChargingProfileId = -1;
  520. defaultTxProfile.ChargingProfileId = -1;
  521. txProfile.ChargingProfileId = -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 max profile
  529. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. maxProfile.ChargingProfileId = -1;
  540. maxProfile.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 MaxProfile 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")) != maxProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.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(maxProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("MaxProfile found.\n");
  574. else
  575. DEBUG_INFO("MaxProfile updated.\n");
  576. // Required item
  577. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)maxProfile.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. 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"));
  584. 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")));
  585. 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?
  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*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)maxProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)maxProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)maxProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. maxProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. maxProfile.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. maxProfile.ChargingSchedule.Duration = -1;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. 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")));
  633. }
  634. else
  635. {
  636. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. maxProfile.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. maxProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(maxProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("MaxProfile found.\n");
  653. else
  654. DEBUG_INFO("MaxProfile updated.\n");
  655. // Required item
  656. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)maxProfile.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. 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"));
  663. 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")));
  664. 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?
  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*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)maxProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)maxProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)maxProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. maxProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. maxProfile.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. maxProfile.ChargingSchedule.Duration = -1;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. 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")));
  712. }
  713. else
  714. {
  715. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. maxProfile.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. maxProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(maxProfile.ChargingProfileId !=-1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("MaxProfile not found.\n");
  757. DEBUG_INFO("------------------------------------\n");*/
  758. }
  759. // Search default tx profile
  760. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  761. if((access(profileFileName, F_OK))==-1)
  762. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  763. if((access(profileFileName, F_OK))!=-1)
  764. {
  765. fp = fopen(profileFileName, "r");
  766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  767. {
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  771. }
  772. defaultTxProfile.ChargingProfileId = -1;
  773. defaultTxProfile.StackLevel = -1;
  774. while(getline(&line, &len, fp) != -1)
  775. {
  776. json_object *obj = NULL;
  777. obj = json_tokener_parse(line);
  778. if(is_error(obj))
  779. {
  780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  781. }
  782. else
  783. {
  784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  786. )
  787. {
  788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  790. )
  791. {
  792. struct tm tmFrom, tmTo;
  793. struct timeb tbFrom, tbTo;
  794. 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) &&
  795. (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))
  796. {
  797. tmFrom.tm_year -= 1900;
  798. tmFrom.tm_mon -= 1;
  799. tbFrom.time = mktime(&tmFrom);
  800. tmTo.tm_year -= 1900;
  801. tmTo.tm_mon -= 1;
  802. tbTo.time = mktime(&tmTo);
  803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  804. {
  805. if(defaultTxProfile.ChargingProfileId == -1)
  806. DEBUG_INFO("TxDefaultProfile found.\n");
  807. else
  808. DEBUG_INFO("TxDefaultProfile updated.\n");
  809. // Required item
  810. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  811. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  812. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  813. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  814. 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++)
  815. {
  816. 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"));
  817. 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")));
  818. 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?
  819. 3:
  820. 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")));
  821. }
  822. // Optional item
  823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  824. {
  825. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  826. }
  827. else
  828. {
  829. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  830. }
  831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  832. {
  833. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  834. }
  835. else
  836. {
  837. sprintf((char*)defaultTxProfile.ValidTo, " ");
  838. }
  839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  840. {
  841. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  842. }
  843. else
  844. {
  845. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  846. }
  847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  848. {
  849. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  850. }
  851. else
  852. {
  853. defaultTxProfile.TransactionId = -1;
  854. }
  855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  856. {
  857. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  858. }
  859. else
  860. {
  861. defaultTxProfile.ChargingSchedule.Duration = -1;
  862. }
  863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  864. {
  865. 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")));
  866. }
  867. else
  868. {
  869. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  870. }
  871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  872. {
  873. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  874. }
  875. else
  876. {
  877. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  878. }
  879. }
  880. }
  881. }
  882. else
  883. {
  884. if(defaultTxProfile.ChargingProfileId == -1)
  885. DEBUG_INFO("TxDefaultProfile found.\n");
  886. else
  887. DEBUG_INFO("TxDefaultProfile updated.\n");
  888. // Required item
  889. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  890. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  891. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  892. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  893. 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++)
  894. {
  895. 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"));
  896. 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")));
  897. 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?
  898. 3:
  899. 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")));
  900. }
  901. // Optional item
  902. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  903. {
  904. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  905. }
  906. else
  907. {
  908. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  909. }
  910. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  911. {
  912. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  913. }
  914. else
  915. {
  916. sprintf((char*)defaultTxProfile.ValidTo, " ");
  917. }
  918. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  919. {
  920. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  921. }
  922. else
  923. {
  924. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  925. }
  926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  927. {
  928. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  929. }
  930. else
  931. {
  932. defaultTxProfile.TransactionId = -1;
  933. }
  934. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  935. {
  936. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  937. }
  938. else
  939. {
  940. defaultTxProfile.ChargingSchedule.Duration = -1;
  941. }
  942. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  943. {
  944. 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")));
  945. }
  946. else
  947. {
  948. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  949. }
  950. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  951. {
  952. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  953. }
  954. else
  955. {
  956. maxProfile.ChargingSchedule.MinChargingRate = -1;
  957. }
  958. }
  959. }
  960. }
  961. json_object_put(obj);
  962. }
  963. fclose(fp);
  964. /*
  965. if(defaultTxProfile.ChargingProfileId != -1)
  966. {
  967. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  968. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  969. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  970. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  971. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  972. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  973. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  974. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  975. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  976. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  977. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  979. {
  980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  981. {
  982. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  983. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  984. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  985. }
  986. }
  987. }
  988. else
  989. DEBUG_INFO("TxDefaultProfile not found.\n");
  990. DEBUG_INFO("------------------------------------\n");*/
  991. }
  992. // Search tx profile
  993. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  994. if((access(profileFileName, F_OK))!=-1)
  995. {
  996. fp = fopen(profileFileName, "r");
  997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  998. {
  999. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1000. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1001. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1002. }
  1003. txProfile.ChargingProfileId = -1;
  1004. txProfile.StackLevel = -1;
  1005. while(getline(&line, &len, fp) != -1)
  1006. {
  1007. json_object *obj = NULL;
  1008. obj = json_tokener_parse(line);
  1009. if(is_error(obj))
  1010. {
  1011. DEBUG_ERROR("Parse txProfile from file error.\n");
  1012. }
  1013. else
  1014. {
  1015. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1016. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1017. )
  1018. {
  1019. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1020. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1021. )
  1022. {
  1023. struct tm tmFrom, tmTo;
  1024. struct timeb tbFrom, tbTo;
  1025. 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) &&
  1026. (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))
  1027. {
  1028. tmFrom.tm_year -= 1900;
  1029. tmFrom.tm_mon -= 1;
  1030. tbFrom.time = mktime(&tmFrom);
  1031. tmTo.tm_year -= 1900;
  1032. tmTo.tm_mon -= 1;
  1033. tbTo.time = mktime(&tmTo);
  1034. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1035. {
  1036. if(txProfile.ChargingProfileId == -1)
  1037. DEBUG_INFO("TxProfile found.\n");
  1038. else
  1039. DEBUG_INFO("TxProfile updated.\n");
  1040. // Required item
  1041. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1042. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1043. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1044. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1045. 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++)
  1046. {
  1047. 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"));
  1048. 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")));
  1049. 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?
  1050. 3:
  1051. 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")));
  1052. }
  1053. // Optional item
  1054. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1055. {
  1056. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1057. }
  1058. else
  1059. {
  1060. sprintf((char*)txProfile.ValidFrom, " ");
  1061. }
  1062. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. {
  1064. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)txProfile.ValidTo, " ");
  1069. }
  1070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1071. {
  1072. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1073. }
  1074. else
  1075. {
  1076. sprintf((char*)txProfile.RecurrencyKind, " ");
  1077. }
  1078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1079. {
  1080. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1081. }
  1082. else
  1083. {
  1084. txProfile.TransactionId = -1;
  1085. }
  1086. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1087. {
  1088. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1089. }
  1090. else
  1091. {
  1092. txProfile.ChargingSchedule.Duration = -1;
  1093. }
  1094. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1095. {
  1096. 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")));
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1101. }
  1102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1103. {
  1104. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1105. }
  1106. else
  1107. {
  1108. txProfile.ChargingSchedule.MinChargingRate = -1;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. else
  1114. {
  1115. if(txProfile.ChargingProfileId == -1)
  1116. DEBUG_INFO("TxProfile found.\n");
  1117. else
  1118. DEBUG_INFO("TxProfile updated.\n");
  1119. // Required item
  1120. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1121. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1122. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1123. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1124. 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++)
  1125. {
  1126. 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"));
  1127. 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")));
  1128. 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?
  1129. 3:
  1130. 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")));
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)txProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)txProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. txProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.Duration = -1;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. 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")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. json_object_put(obj);
  1193. }
  1194. fclose(fp);
  1195. /*
  1196. if(defaultTxProfile.ChargingProfileId != -1)
  1197. {
  1198. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1199. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1200. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1201. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1202. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1203. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1204. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1205. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1206. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1207. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1208. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1209. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1210. {
  1211. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1212. {
  1213. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1214. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1215. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1216. }
  1217. }
  1218. }
  1219. else
  1220. DEBUG_INFO("TxProfile not found.\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(maxProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(maxProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. }
  1250. }
  1251. }
  1252. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1253. {
  1254. if(maxProfile.ChargingSchedule.Duration != -1)
  1255. {
  1256. 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?
  1257. 0:
  1258. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1259. }
  1260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1261. {
  1262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1263. {
  1264. 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?
  1265. 0:
  1266. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1273. {
  1274. if(maxProfile.ChargingSchedule.Duration != -1)
  1275. {
  1276. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1277. 0:
  1278. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1279. }
  1280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1281. {
  1282. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1283. {
  1284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1285. 0:
  1286. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. if(maxProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1295. 0:
  1296. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1303. 0:
  1304. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1305. }
  1306. }
  1307. }
  1308. }
  1309. /*
  1310. DEBUG_INFO("MaxProfile after align.\n");
  1311. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1312. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1313. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1314. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1315. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1316. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1317. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1318. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1319. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1320. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1321. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1322. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1323. {
  1324. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1325. {
  1326. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1327. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1328. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1329. }
  1330. }
  1331. DEBUG_INFO("------------------------------------\n");*/
  1332. }
  1333. if(defaultTxProfile.ChargingProfileId != -1)
  1334. {
  1335. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1336. {
  1337. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1340. 0:
  1341. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1342. }
  1343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1344. {
  1345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1346. {
  1347. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1348. 0:
  1349. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1350. }
  1351. }
  1352. }
  1353. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1354. {
  1355. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1356. {
  1357. 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?
  1358. 0:
  1359. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1360. }
  1361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1362. {
  1363. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1364. {
  1365. 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?
  1366. 0:
  1367. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1368. }
  1369. }
  1370. }
  1371. else
  1372. {
  1373. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1374. {
  1375. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1376. {
  1377. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1378. 0:
  1379. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1380. }
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1386. 0:
  1387. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1388. }
  1389. }
  1390. }
  1391. else
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(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 = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1406. }
  1407. }
  1408. }
  1409. }
  1410. /*
  1411. DEBUG_INFO("defaultTxProfile after align.\n");
  1412. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1413. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1414. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1415. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1416. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1417. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1418. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1419. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1420. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1421. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1422. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1424. {
  1425. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1426. {
  1427. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1428. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1429. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1430. }
  1431. }
  1432. DEBUG_INFO("------------------------------------\n");*/
  1433. }
  1434. if(txProfile.ChargingProfileId != -1)
  1435. {
  1436. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1437. {
  1438. if(txProfile.ChargingSchedule.Duration != -1)
  1439. {
  1440. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1441. 0:
  1442. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1443. }
  1444. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1445. {
  1446. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1447. {
  1448. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1449. 0:
  1450. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1451. }
  1452. }
  1453. }
  1454. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1455. {
  1456. if(txProfile.ChargingSchedule.Duration != -1)
  1457. {
  1458. 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?
  1459. 0:
  1460. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1461. }
  1462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1463. {
  1464. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1465. {
  1466. 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?
  1467. 0:
  1468. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1469. }
  1470. }
  1471. }
  1472. else
  1473. {
  1474. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1475. {
  1476. if(txProfile.ChargingSchedule.Duration != -1)
  1477. {
  1478. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1479. 0:
  1480. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1481. }
  1482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1483. {
  1484. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1485. {
  1486. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1487. 0:
  1488. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1489. }
  1490. }
  1491. }
  1492. else
  1493. {
  1494. if(txProfile.ChargingSchedule.Duration != -1)
  1495. {
  1496. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1497. 0:
  1498. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1499. }
  1500. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1501. {
  1502. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1503. {
  1504. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1505. 0:
  1506. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1507. }
  1508. }
  1509. }
  1510. }
  1511. /*
  1512. DEBUG_INFO("txProfile after align.\n");
  1513. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1514. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1515. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1516. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1517. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1518. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1519. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1520. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1521. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1522. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1523. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1524. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1525. {
  1526. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1527. {
  1528. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1529. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1530. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1531. }
  1532. }*/
  1533. }
  1534. /*
  1535. * Merge to conposite schedule
  1536. */
  1537. //DEBUG_INFO("====================================\n");
  1538. // Find each profile period quantity
  1539. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1540. {
  1541. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1542. limitMax = idx+1;
  1543. }
  1544. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1545. {
  1546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1547. limitDef = idx+1;
  1548. }
  1549. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1550. {
  1551. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1552. limitTx = idx+1;
  1553. }
  1554. // TxProfile found, composite schedule based on it
  1555. if(txProfile.ChargingProfileId != -1)
  1556. {
  1557. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1558. {
  1559. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1560. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1561. (txProfile.ChargingSchedule.Duration > 0))
  1562. {
  1563. if(maxProfile.ChargingProfileId != -1)
  1564. {
  1565. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1566. {
  1567. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1568. {
  1569. if((maxProfile.ChargingSchedule.Duration > 0))
  1570. {
  1571. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1572. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1573. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1574. }
  1575. else
  1576. {
  1577. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1578. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1579. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1580. }
  1581. }
  1582. if(idxMaxPeriod == (limitMax-1))
  1583. {
  1584. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1585. {
  1586. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1587. {
  1588. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1589. compositePeriodIdx++;
  1590. }
  1591. else
  1592. {
  1593. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. else
  1600. {
  1601. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1602. {
  1603. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1604. compositePeriodIdx++;
  1605. }
  1606. else
  1607. {
  1608. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1609. }
  1610. }
  1611. }
  1612. if(idxTxPeriod == (limitTx-1))
  1613. {
  1614. if(defaultTxProfile.ChargingProfileId != -1)
  1615. {
  1616. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1617. {
  1618. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1619. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1620. {
  1621. if(maxProfile.ChargingProfileId != -1)
  1622. {
  1623. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1624. {
  1625. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1626. {
  1627. if((maxProfile.ChargingSchedule.Duration > 0))
  1628. {
  1629. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1630. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1631. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1632. }
  1633. else
  1634. {
  1635. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1636. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1637. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1638. }
  1639. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1640. {
  1641. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1642. {
  1643. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1644. compositePeriodIdx++;
  1645. }
  1646. else
  1647. {
  1648. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1649. }
  1650. }
  1651. break;
  1652. }
  1653. }
  1654. }
  1655. else
  1656. {
  1657. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1658. {
  1659. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1660. compositePeriodIdx++;
  1661. }
  1662. else
  1663. {
  1664. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }
  1670. }
  1671. }
  1672. }
  1673. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1674. else if(defaultTxProfile.ChargingProfileId != -1)
  1675. {
  1676. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1677. {
  1678. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1679. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1680. {
  1681. if(maxProfile.ChargingProfileId != -1)
  1682. {
  1683. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1684. {
  1685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1686. {
  1687. if((maxProfile.ChargingSchedule.Duration > 0))
  1688. {
  1689. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1690. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1691. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1692. }
  1693. else
  1694. {
  1695. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1696. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1697. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1698. }
  1699. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1700. {
  1701. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. break;
  1712. }
  1713. }
  1714. }
  1715. else
  1716. {
  1717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1718. {
  1719. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1720. compositePeriodIdx++;
  1721. }
  1722. else
  1723. {
  1724. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. // Fill other period by MaxProfile
  1731. if(maxProfile.ChargingProfileId != -1)
  1732. {
  1733. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1734. {
  1735. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1736. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  1737. {
  1738. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1739. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1740. {
  1741. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1742. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1743. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1744. }
  1745. if(idxMaxPeriod == (limitMax-1))
  1746. {
  1747. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1748. (maxProfile.ChargingSchedule.Duration > 0))
  1749. {
  1750. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1751. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1752. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1753. }
  1754. if(tmpPeriod.Limit != -1)
  1755. {
  1756. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1757. {
  1758. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1774. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1775. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1776. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1777. {
  1778. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1779. {
  1780. compositeProfile->ChargingProfileId = 1;
  1781. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1782. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1783. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1784. }
  1785. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1786. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1787. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1788. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1789. }
  1790. if(line)
  1791. free(line);
  1792. }
  1793. //==========================================
  1794. // Init all share memory
  1795. //==========================================
  1796. int InitShareMemory()
  1797. {
  1798. int result = PASS;
  1799. int MeterSMId;
  1800. //creat ShmSysConfigAndInfo
  1801. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1802. {
  1803. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1804. result = FAIL;
  1805. }
  1806. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1807. {
  1808. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1809. result = FAIL;
  1810. }
  1811. else
  1812. {}
  1813. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1814. {
  1815. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1816. result = FAIL;
  1817. }
  1818. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1819. {
  1820. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1821. result = FAIL;
  1822. }
  1823. else
  1824. {}
  1825. //creat ShmPsuData
  1826. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1827. {
  1828. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1829. result = FAIL;
  1830. }
  1831. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1832. {
  1833. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1834. result = FAIL;
  1835. }
  1836. else
  1837. {}
  1838. //creat ShmOCPP16Data
  1839. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1840. {
  1841. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1842. result = FAIL;
  1843. }
  1844. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1845. {
  1846. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1847. result = FAIL;
  1848. }
  1849. else
  1850. {}
  1851. /****************************** For Initial Settings************************************************/
  1852. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1853. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1854. // allocate Configuration memory address
  1855. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1856. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1857. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1858. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1859. //offline MeterValue Interval
  1860. TempMeterValueInterval = 0;
  1861. return result;
  1862. }
  1863. int ProcessShareMemory()
  1864. {
  1865. if(InitShareMemory() == FAIL)
  1866. {
  1867. DEBUG_ERROR("InitShareMemory NG\n");
  1868. if(ShmStatusCodeData!=NULL)
  1869. {
  1870. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1871. }
  1872. sleep(5);
  1873. return FAIL;
  1874. }
  1875. return PASS;
  1876. }
  1877. //---------------------common routine---------------------------//
  1878. int isOFFline(void)
  1879. {
  1880. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1881. {
  1882. if(TempMeterValueInterval >= 2 )
  1883. {
  1884. TempMeterValueInterval = 0;
  1885. return TRUE;
  1886. }
  1887. else
  1888. {
  1889. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1890. return FALSE;
  1891. }
  1892. }
  1893. else
  1894. {
  1895. return FALSE;
  1896. }
  1897. }
  1898. //---------------------------------------------
  1899. // new:
  1900. // enum SYSTEM_STATUS
  1901. // {
  1902. // SYS_MODE_BOOTING = 0,
  1903. // SYS_MODE_IDLE = 1,
  1904. // SYS_MODE_AUTHORIZING = 2,
  1905. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1906. // SYS_MODE_REASSIGN = 4,
  1907. // SYS_MODE_PREPARING = 5,
  1908. // SYS_MODE_PREPARE_FOR_EV = 6,
  1909. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1910. // SYS_MODE_CHARGING = 8,
  1911. // SYS_MODE_TERMINATING = 9,
  1912. // SYS_MODE_COMPLETE = 10,
  1913. // SYS_MODE_ALARM = 11,
  1914. // SYS_MODE_FAULT = 12,
  1915. // SYS_MODE_RESERVATION = 13,
  1916. // SYS_MODE_BOOKING = 14,
  1917. // SYS_MODE_MAINTAIN = 15,
  1918. // SYS_MODE_DEBUG = 16,
  1919. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1920. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1921. // SYS_MODE_UPDATE = 19
  1922. // };
  1923. //
  1924. //
  1925. //-----------------------------------------
  1926. void CheckSystemValue(void)
  1927. {
  1928. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1929. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1930. char filenmae[100]={0};
  1931. char str[100]={0};
  1932. int tempIndex = 0;
  1933. //===============================
  1934. // send Heartbeat
  1935. //===============================
  1936. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1937. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1938. {
  1939. clientTime.Heartbeat=time((time_t*)NULL);
  1940. if(server_sign == TRUE)
  1941. {
  1942. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1943. }
  1944. else
  1945. {
  1946. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  1947. }
  1948. }
  1949. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1950. {
  1951. //parameter for test
  1952. sendHeartbeatRequest(0);
  1953. //==============================================
  1954. // Reset Waiting Time
  1955. //==============================================
  1956. clientTime.Heartbeat=time((time_t*)NULL);
  1957. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1958. }
  1959. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1960. {
  1961. //===============================
  1962. // CSU Trigger Reset Conf
  1963. //===============================
  1964. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1965. {
  1966. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1967. }
  1968. //===============================
  1969. // CSU Trigger Authorize Request
  1970. //===============================
  1971. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1972. {
  1973. sendAuthorizeRequest(0);
  1974. authorizeRetryTimes = authorizeRetryTimes + 1;
  1975. if(authorizeRetryTimes < 3)
  1976. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1977. }
  1978. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  1979. {
  1980. authorizeRetryTimes = 0;
  1981. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1982. server_sign = FALSE;
  1983. }
  1984. 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))
  1985. {
  1986. sendAuthorizeRequest(0);
  1987. }
  1988. //===============================
  1989. // CSU Trigger Smart Charging Profilw
  1990. //===============================
  1991. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1992. {
  1993. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1994. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  1995. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1996. }
  1997. //==============================================
  1998. // Charger start transaction
  1999. //==============================================
  2000. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2001. {
  2002. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2003. sendStartTransactionRequest(gun_index);
  2004. clientTime.StartTransaction = time((time_t*)NULL);
  2005. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2006. }
  2007. //==============================================
  2008. // Charger stop transaction
  2009. //==============================================
  2010. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2011. {
  2012. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2013. sendStopTransactionRequest(gun_index);
  2014. clientTime.StopTransaction = time((time_t*)NULL);
  2015. }
  2016. //==============================================
  2017. // Charger status report
  2018. //==============================================
  2019. //--- Check Mode Change ---//
  2020. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2021. if(gunType[gun_index] == 'J')
  2022. {
  2023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2024. {
  2025. tempIndex = ((gun_index==2) ? 1: 0);
  2026. }
  2027. else
  2028. {
  2029. tempIndex = gun_index;
  2030. }
  2031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2032. {
  2033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2034. {
  2035. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2036. {
  2037. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2038. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2039. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2040. statusModeChage[gun_index] = TRUE;
  2041. }
  2042. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2043. {
  2044. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2045. if((access(filenmae,F_OK))!=-1)
  2046. {
  2047. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2048. sprintf(str,"rm -f %s",filenmae);
  2049. system(str);
  2050. }
  2051. }
  2052. #if 1 // for TempStopTransaction
  2053. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2054. {
  2055. checkTempStopTransaction(gun_index);
  2056. }
  2057. #endif
  2058. }
  2059. }
  2060. }
  2061. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2062. {
  2063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2064. {
  2065. tempIndex = ((gun_index==2) ? 1: 0);
  2066. }
  2067. else
  2068. {
  2069. tempIndex = gun_index;
  2070. }
  2071. for (int index = 0; index < CCS_QUANTITY; index++)
  2072. {
  2073. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2074. {
  2075. 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]*/ )
  2076. {
  2077. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2078. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2079. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2080. statusModeChage[gun_index] = TRUE;
  2081. }
  2082. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2083. {
  2084. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2085. if((access(filenmae,F_OK))!=-1)
  2086. {
  2087. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2088. sprintf(str,"rm -f %s",filenmae);
  2089. system(str);
  2090. }
  2091. }
  2092. #if 1 // for TempStopTransaction
  2093. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2094. {
  2095. checkTempStopTransaction(gun_index);
  2096. }
  2097. #endif
  2098. }
  2099. }
  2100. }
  2101. else if(gunType[gun_index] == 'G')
  2102. {
  2103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2104. {
  2105. tempIndex = ((gun_index==2) ? 1: 0);
  2106. }
  2107. else
  2108. {
  2109. tempIndex = gun_index;
  2110. }
  2111. for (int index = 0; index < GB_QUANTITY; index++)
  2112. {
  2113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2114. {
  2115. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2116. {
  2117. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2118. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2119. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2120. statusModeChage[gun_index] = TRUE;
  2121. }
  2122. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2123. {
  2124. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2125. if((access(filenmae,F_OK))!=-1)
  2126. {
  2127. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2128. sprintf(str,"rm -f %s",filenmae);
  2129. system(str);
  2130. }
  2131. }
  2132. #if 1 // for TempStopTransaction
  2133. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2134. {
  2135. checkTempStopTransaction(gun_index);
  2136. }
  2137. #endif
  2138. }
  2139. }
  2140. }
  2141. else
  2142. {
  2143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2144. {
  2145. tempIndex = 2;
  2146. }
  2147. else
  2148. {
  2149. tempIndex = gun_index;
  2150. }
  2151. for (int index = 0; index < AC_QUANTITY; index++)
  2152. {
  2153. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2154. {
  2155. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2156. {
  2157. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2158. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2160. statusModeChage[gun_index] = TRUE;
  2161. }
  2162. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2163. {
  2164. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2165. if((access(filenmae,F_OK))!=-1)
  2166. {
  2167. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2168. sprintf(str,"rm -f %s",filenmae);
  2169. system(str);
  2170. }
  2171. }
  2172. #if 1 // for TempStopTransaction
  2173. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2174. {
  2175. checkTempStopTransaction(gun_index);
  2176. }
  2177. #endif
  2178. }
  2179. }// END
  2180. }
  2181. if(isWebsocketSendable &&
  2182. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2183. {
  2184. if(SystemInitial > 0)
  2185. SystemInitial -= 1;
  2186. sendStatusNotificationRequest(gun_index);
  2187. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2188. statusModeChage[gun_index] = FALSE;
  2189. }
  2190. //==============================================
  2191. // Meter report
  2192. //==============================================
  2193. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2194. (((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)))
  2195. {
  2196. //check Transaction active
  2197. if(gunType[gun_index] == 'J')
  2198. {
  2199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2200. {
  2201. tempIndex = ((gun_index==2) ? 1: 0);
  2202. }
  2203. else
  2204. {
  2205. tempIndex = gun_index;
  2206. }
  2207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2208. {
  2209. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2210. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2211. {
  2212. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2213. {
  2214. reqSampleMeter[gun_index] = 1;
  2215. }
  2216. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2217. {
  2218. reqClockAlignMeter[gun_index] = 1;
  2219. }
  2220. }
  2221. }// End for CHAdeMO
  2222. }
  2223. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2224. {
  2225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2226. {
  2227. tempIndex = ((gun_index==2) ? 1: 0);
  2228. }
  2229. else
  2230. {
  2231. tempIndex = gun_index;
  2232. }
  2233. for (int index = 0; index < CCS_QUANTITY; index++)
  2234. {
  2235. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2236. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2237. {
  2238. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2239. {
  2240. reqSampleMeter[gun_index] = 1;
  2241. }
  2242. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2243. {
  2244. reqClockAlignMeter[gun_index] = 1;
  2245. }
  2246. }
  2247. } // End for CCS
  2248. }
  2249. else if(gunType[gun_index] == 'G')
  2250. {
  2251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2252. {
  2253. tempIndex = ((gun_index==2) ? 1: 0);
  2254. }
  2255. else
  2256. {
  2257. tempIndex = gun_index;
  2258. }
  2259. for (int index = 0; index < GB_QUANTITY; index++)
  2260. {
  2261. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2262. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2263. {
  2264. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2265. {
  2266. reqSampleMeter[gun_index] = 1;
  2267. }
  2268. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2269. {
  2270. reqClockAlignMeter[gun_index] = 1;
  2271. }
  2272. }
  2273. }// End for GB
  2274. }
  2275. else
  2276. {
  2277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2278. {
  2279. tempIndex = 2;
  2280. }
  2281. else
  2282. {
  2283. tempIndex = gun_index;
  2284. }
  2285. for (int index = 0; index < AC_QUANTITY; index++)
  2286. {
  2287. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2288. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2289. {
  2290. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2291. {
  2292. reqSampleMeter[gun_index] = 1;
  2293. }
  2294. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2295. {
  2296. reqClockAlignMeter[gun_index] = 1;
  2297. }
  2298. }
  2299. }//End for AC
  2300. }
  2301. if(reqSampleMeter[gun_index] == 1)
  2302. {
  2303. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2304. storeTempStopTransaction(gun_index);
  2305. }
  2306. else if(reqClockAlignMeter[gun_index] == 1)
  2307. {
  2308. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2309. }
  2310. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2311. sleep(1);
  2312. }
  2313. //==============================================
  2314. // Check Connector reserved
  2315. //==============================================
  2316. //===============================
  2317. // Check if Reserve is expired
  2318. //===============================
  2319. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2320. {
  2321. double diff_t;
  2322. struct tm tp;
  2323. // current time
  2324. time_t t = time(NULL);
  2325. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2326. tp.tm_isdst = -1;
  2327. time_t utc = mktime(&tp);
  2328. diff_t = difftime(utc, t);
  2329. if(diff_t <= 0)
  2330. {
  2331. DEBUG_INFO("reserve expired.\n");
  2332. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2333. }
  2334. }//END OF Check if Reserve is expired
  2335. //==========================================
  2336. // csu trigger FirmwareStatusNotificationReq
  2337. //==========================================
  2338. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2339. {
  2340. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2341. }
  2342. //==========================================
  2343. // csu trigger CancelReservationConf
  2344. //==========================================
  2345. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2346. {
  2347. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2348. }
  2349. //==========================================
  2350. // csu trigger ChangeAvailabilityConf
  2351. //==========================================
  2352. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2353. {
  2354. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2355. }
  2356. //==========================================
  2357. // csu trigger UnlockConnectorConf
  2358. //==========================================
  2359. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2360. {
  2361. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2362. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2363. }
  2364. //==========================================
  2365. // csu trigger ReserveNowConf
  2366. //==========================================
  2367. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2368. {
  2369. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2370. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2371. }
  2372. //==========================================
  2373. // csu trigger DataTransferReq
  2374. //==========================================
  2375. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2376. {
  2377. sendDataTransferRequest(gun_index);
  2378. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2379. }
  2380. }
  2381. }
  2382. //==========================================
  2383. // send request routine
  2384. //==========================================
  2385. int sendAuthorizeRequest(int gun_index)
  2386. {
  2387. mtrace();
  2388. int result = FAIL;
  2389. char message[100]={0};
  2390. char guid[37];
  2391. char tempdata[65]={0};
  2392. DEBUG_INFO("sendAuthorizeRequest...\n");
  2393. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2394. //Local Authorize
  2395. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2396. {
  2397. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2398. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2399. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2400. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2401. result = PASS;
  2402. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2403. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2404. authorizeRetryTimes = 0;
  2405. return result;
  2406. }
  2407. 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))||
  2408. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2409. {
  2410. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2411. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2412. {
  2413. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2414. {
  2415. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2416. }
  2417. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2418. {
  2419. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2420. }
  2421. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2425. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2426. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2427. authorizeRetryTimes = 0;
  2428. return result;
  2429. }
  2430. else
  2431. {
  2432. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2433. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2434. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2435. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2436. result = PASS;
  2437. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2438. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2439. authorizeRetryTimes = 0;
  2440. return result;
  2441. }
  2442. }
  2443. //initailize struct Authorize
  2444. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2445. //get data from shared memory
  2446. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2447. random_uuid(guid);
  2448. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2449. LWS_Send(message);
  2450. sprintf(tempdata, "Authorize,%d", gun_index);
  2451. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2452. {
  2453. result = PASS;
  2454. DEBUG_INFO("Authorize mapItem pass\n");
  2455. }
  2456. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2457. return result;
  2458. }
  2459. int sendBootNotificationRequest(void)
  2460. {
  2461. mtrace();
  2462. int result = FAIL;
  2463. char message[500]={0}, payload[700]={0};
  2464. char guid[37]={0};
  2465. char tempdata[65]={0};
  2466. /*
  2467. int IsGunCharging = FALSE;
  2468. //check Transaction active
  2469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2470. {
  2471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2472. {
  2473. IsGunCharging = TRUE;
  2474. }
  2475. }
  2476. for (int index = 0; index < CCS_QUANTITY; index++)
  2477. {
  2478. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2479. {
  2480. IsGunCharging = TRUE;
  2481. }
  2482. }
  2483. for (int index = 0; index < GB_QUANTITY; index++)
  2484. {
  2485. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2486. {
  2487. IsGunCharging = TRUE;
  2488. }
  2489. }
  2490. for (int index = 0; index < AC_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2493. {
  2494. IsGunCharging = TRUE;
  2495. }
  2496. }
  2497. if(IsGunCharging == TRUE)
  2498. {
  2499. server_sign = TRUE;
  2500. return result;
  2501. }
  2502. */
  2503. // Fill BootNotification fields
  2504. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2505. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2506. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2507. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2508. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2509. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2510. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2511. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2512. ShmOCPP16Data->ChargeBoxId
  2513. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2514. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2515. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2516. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2517. ,ShmOCPP16Data->BootNotification.CpIccid
  2518. ,ShmOCPP16Data->BootNotification.CpImsi);
  2519. random_uuid(guid);
  2520. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2521. LWS_Send(message);
  2522. sprintf(tempdata, "BootNotification,0");
  2523. 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*/)
  2524. {
  2525. result = PASS;
  2526. }
  2527. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2528. strcpy(queuedata,message);
  2529. return result;
  2530. }
  2531. int sendDataTransferRequest(int gun_index)
  2532. {
  2533. mtrace();
  2534. char message[1000]={0};
  2535. char guid[37]={0};
  2536. char tempdata[65]={0};
  2537. int result = FAIL;
  2538. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2539. random_uuid(guid);
  2540. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2541. MESSAGE_TYPE_CALL,
  2542. guid,
  2543. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2544. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2545. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2546. LWS_Send(message);
  2547. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2548. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2549. {
  2550. result = PASS;
  2551. DEBUG_INFO("DataTransfer mapItem pass\n");
  2552. }
  2553. return result;
  2554. }
  2555. int sendDiagnosticsStatusNotificationRequest(char *status)
  2556. {
  2557. mtrace();
  2558. int result = FAIL;
  2559. char message[110]={0};
  2560. char guid[37]={0};
  2561. char tempdata[65]={0};
  2562. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2563. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2564. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2565. random_uuid(guid);
  2566. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2567. LWS_Send(message);
  2568. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2569. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2570. {
  2571. result = PASS;
  2572. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2573. }
  2574. //#ifdef SystemLogMessage
  2575. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2576. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2577. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2578. //#endif
  2579. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2580. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2581. //record status
  2582. if(strcmp(status,"Idle")==0)
  2583. {
  2584. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2585. }
  2586. else if(strcmp(status,"Uploaded")==0)
  2587. {
  2588. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2589. }
  2590. else if(strcmp(status,"UploadFailed")==0)
  2591. {
  2592. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2593. }
  2594. else if(strcmp(status,"Uploading")==0)
  2595. {
  2596. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2597. }
  2598. return result;
  2599. }
  2600. int sendFirmwareStatusNotificationRequest(char *status)
  2601. {
  2602. mtrace();
  2603. int result = FAIL;
  2604. char message[110]={0};
  2605. char guid[37]={0};
  2606. char tempdata[65]={0};
  2607. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2608. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2609. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2610. random_uuid(guid);
  2611. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2612. LWS_Send(message);
  2613. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2614. 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*/)
  2615. {
  2616. result = PASS;
  2617. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2618. }
  2619. //#ifdef SystemLogMessage
  2620. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2621. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2622. //#endif
  2623. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2624. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2625. //record status
  2626. if(strcmp(status,"Downloaded")==0)
  2627. {
  2628. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2629. }
  2630. else if(strcmp(status,"DownloadFailed")==0)
  2631. {
  2632. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2633. }
  2634. else if(strcmp(status,"Downloading")==0)
  2635. {
  2636. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2637. }
  2638. else if(strcmp(status,"Idle")==0)
  2639. {
  2640. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2641. }
  2642. else if(strcmp(status,"InstallationFailed")==0)
  2643. {
  2644. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2645. }
  2646. else if(strcmp(status,"Installing")==0)
  2647. {
  2648. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2649. }
  2650. else if(strcmp(status,"Installed")==0)
  2651. {
  2652. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2653. }
  2654. return result;
  2655. }
  2656. int sendHeartbeatRequest(int gun_index)
  2657. {
  2658. mtrace();
  2659. int result = FAIL;
  2660. char message[80]={0};
  2661. char guid[37]={0};
  2662. char tempdata[65]={0};
  2663. random_uuid(guid);
  2664. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2665. , MESSAGE_TYPE_CALL
  2666. , guid );
  2667. LWS_Send(message);
  2668. sprintf(tempdata, "Heartbeat,%d", 0);
  2669. 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*/)
  2670. {
  2671. result = PASS;
  2672. }
  2673. return result;
  2674. }
  2675. int sendStartTransactionRequest(int gun_index)
  2676. {
  2677. mtrace();
  2678. int result = FAIL;
  2679. char message[250]={0};
  2680. char guid[37]={0};
  2681. struct timeval tmnow;
  2682. struct tm *tm;
  2683. char buf[28];//, usec_buf[6];
  2684. char tempdata[65]={0};
  2685. int tempIndex = 0;
  2686. DEBUG_INFO("sendStartTransactionRequest...\n");
  2687. gettimeofday(&tmnow, NULL);
  2688. time_t t;
  2689. t = time(NULL);
  2690. /*UTC time and date*/
  2691. tm = gmtime(&t);
  2692. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2693. #if 0 // remove temporally
  2694. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2695. strcat(buf,".");
  2696. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2697. strcat(buf,usec_buf);
  2698. #endif
  2699. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2700. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2701. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2702. // clear StartTransaction Response
  2703. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2704. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2705. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2706. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2708. if(gunType[gun_index] == 'J')
  2709. {
  2710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2711. {
  2712. tempIndex = ((gun_index==2) ? 1: 0);
  2713. }
  2714. else
  2715. {
  2716. tempIndex = gun_index;
  2717. }
  2718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2719. {
  2720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2721. {
  2722. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2723. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2724. }
  2725. }
  2726. }
  2727. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2728. {
  2729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2730. {
  2731. tempIndex = ((gun_index==2) ? 1: 0);
  2732. }
  2733. else
  2734. {
  2735. tempIndex = gun_index;
  2736. }
  2737. for (int index = 0; index < CCS_QUANTITY; index++)
  2738. {
  2739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2740. {
  2741. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2742. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2743. }
  2744. }
  2745. }
  2746. else if(gunType[gun_index] == 'G')
  2747. {
  2748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2749. {
  2750. tempIndex = ((gun_index==2) ? 1: 0);
  2751. }
  2752. else
  2753. {
  2754. tempIndex = gun_index;
  2755. }
  2756. for (int index = 0; index < GB_QUANTITY; index++)
  2757. {
  2758. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2759. {
  2760. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2761. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2762. }
  2763. }
  2764. }
  2765. else
  2766. {
  2767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2768. {
  2769. tempIndex = 2;
  2770. }
  2771. else
  2772. {
  2773. tempIndex = gun_index;
  2774. }
  2775. for (int index = 0; index < AC_QUANTITY; index++)
  2776. {
  2777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2778. {
  2779. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2780. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2781. }
  2782. }
  2783. }
  2784. random_uuid(guid);
  2785. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2786. {
  2787. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2788. , gun_index +1
  2789. , MESSAGE_TYPE_CALL
  2790. , guid
  2791. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2792. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2793. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2794. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2795. }
  2796. else
  2797. {
  2798. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2799. , gun_index +1
  2800. , MESSAGE_TYPE_CALL
  2801. , guid
  2802. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2803. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2804. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2805. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2806. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2807. }
  2808. #if 1
  2809. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2810. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2811. {
  2812. result = PASS;
  2813. }
  2814. #endif
  2815. strcpy(queuedata, message);
  2816. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2817. /*
  2818. if(GetTransactionQueueNum() == 1)
  2819. {
  2820. LWS_Send(message + 2);
  2821. }*/
  2822. return result;
  2823. }
  2824. int sendStatusNotificationRequest(int gun_index)
  2825. {
  2826. mtrace();
  2827. int result = FAIL;
  2828. char message[600]={0};
  2829. char guid[37];
  2830. int currentStatus = 0;
  2831. struct timeval tmnow;
  2832. struct tm *tm;
  2833. char buf[28];//, usec_buf[6];
  2834. char tempdata[65]={0};
  2835. int tempIndex = 0;
  2836. gettimeofday(&tmnow, NULL);
  2837. time_t t;
  2838. t = time(NULL);
  2839. /*UTC time and date*/
  2840. tm = gmtime(&t);
  2841. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2842. #if 0 // remove temporally
  2843. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2844. strcat(buf,".");
  2845. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2846. strcat(buf,usec_buf);
  2847. #endif
  2848. printf("%s",buf);
  2849. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2850. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2851. // it's option
  2852. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2853. /*
  2854. enum _SYSTEM_STATUS
  2855. {
  2856. S_BOOTING = 0,
  2857. S_IDLE, = 1
  2858. S_AUTHORIZING, =2
  2859. S_REASSIGN_CHECK, =3
  2860. S_REASSIGN, =4
  2861. S_PRECHARGE, =5
  2862. S_PREPARING_FOR_EV, =6
  2863. S_PREPARING_FOR_EVSE, =7
  2864. S_CHARGING, =8
  2865. S_TERMINATING, =9
  2866. S_COMPLETE, =10
  2867. S_ALARM, =11
  2868. S_FAULT =12
  2869. }
  2870. */
  2871. //check Transaction active
  2872. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2873. if(gunType[gun_index] == 'J')
  2874. {
  2875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2876. {
  2877. tempIndex = ((gun_index==2) ? 1: 0);
  2878. }
  2879. else
  2880. {
  2881. tempIndex = gun_index;
  2882. }
  2883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2884. {
  2885. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2886. {
  2887. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2888. {
  2889. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2890. {
  2891. currentStatus = 1; //OCPP Status: Preparing
  2892. }
  2893. else
  2894. {
  2895. currentStatus = 0; //OCPP Status: Available
  2896. }
  2897. }
  2898. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2899. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2900. ) //S_PRECHARGE
  2901. {
  2902. currentStatus = 1; //OCPP Status: Preparing
  2903. }
  2904. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2905. {
  2906. currentStatus = 2; //OCPP Status: Charging
  2907. }
  2908. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2909. {
  2910. currentStatus = 5; //OCPP Status: Finishing
  2911. }
  2912. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2913. {
  2914. currentStatus = 4; //OCPP Status: SuspendedEV
  2915. }
  2916. 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
  2917. {
  2918. currentStatus = 7; //OCPP Status: Unavailable
  2919. }
  2920. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2921. {
  2922. currentStatus = 8; //OCPP Status: Faulted
  2923. }
  2924. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2925. {
  2926. currentStatus = 6; //OCPP Status: Reserved
  2927. }
  2928. } //end of the same index
  2929. }//end of for CHAdeMO_QUANTITY
  2930. }
  2931. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2932. {
  2933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2934. {
  2935. tempIndex = ((gun_index==2) ? 1: 0);
  2936. }
  2937. else
  2938. {
  2939. tempIndex = gun_index;
  2940. }
  2941. for (int index = 0; index < CCS_QUANTITY; index++)
  2942. {
  2943. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2944. {
  2945. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2946. {
  2947. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  2948. {
  2949. currentStatus = 1; //OCPP Status: Preparing
  2950. }
  2951. else
  2952. {
  2953. currentStatus = 0; //OCPP Status: Available
  2954. }
  2955. }
  2956. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2957. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2958. ) //S_PRECHARGE
  2959. {
  2960. currentStatus = 1; //OCPP Status: Preparing
  2961. }
  2962. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2963. {
  2964. currentStatus = 2; //OCPP Status: Charging
  2965. }
  2966. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2967. {
  2968. currentStatus = 5; //OCPP Status: Finishing
  2969. }
  2970. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  2971. {
  2972. currentStatus = 4; //OCPP Status: SuspendedEV
  2973. }
  2974. 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
  2975. {
  2976. currentStatus = 7; //OCPP Status : Unavailable
  2977. }
  2978. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2979. {
  2980. currentStatus = 8; //OCPP Status: Faulted
  2981. }
  2982. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2983. {
  2984. currentStatus = 6; //OCPP Status: Reserved
  2985. }
  2986. } //end of the same index
  2987. } // end of for CCS_QUANTITY
  2988. }
  2989. else if(gunType[gun_index] == 'G')
  2990. {
  2991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2992. {
  2993. tempIndex = ((gun_index==2) ? 1: 0);
  2994. }
  2995. else
  2996. {
  2997. tempIndex = gun_index;
  2998. }
  2999. for (int index = 0; index < GB_QUANTITY; index++)
  3000. {
  3001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3002. {
  3003. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3004. {
  3005. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3006. {
  3007. currentStatus = 1; //OCPP Status: Preparing
  3008. }
  3009. else
  3010. {
  3011. currentStatus = 0; //OCPP Status: Available
  3012. }
  3013. }
  3014. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3015. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3016. ) //S_PRECHARGE
  3017. {
  3018. currentStatus = 1; //OCPP Status: Preparing
  3019. }
  3020. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3021. {
  3022. currentStatus = 2; //OCPP Status: Charging
  3023. }
  3024. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3025. {
  3026. currentStatus = 5; //OCPP Status: Finishing
  3027. }
  3028. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3029. {
  3030. currentStatus = 4; //OCPP Status: SuspendedEV
  3031. }
  3032. 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
  3033. {
  3034. currentStatus = 7; //OCPP Status: Unavailable
  3035. }
  3036. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3037. {
  3038. currentStatus = 8; //OCPP Status: Faulted
  3039. }
  3040. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3041. {
  3042. currentStatus = 6; //OCPP Status: Reserved
  3043. }
  3044. } //end of the same index
  3045. } // end of for GB_QUANTITY
  3046. }
  3047. else
  3048. {
  3049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3050. {
  3051. tempIndex = 2;
  3052. }
  3053. else
  3054. {
  3055. tempIndex = gun_index;
  3056. }
  3057. for (int index = 0; index < AC_QUANTITY; index++)
  3058. {
  3059. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3060. {
  3061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3062. {
  3063. 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))
  3064. {
  3065. currentStatus = 1; //OCPP Status: Preparing
  3066. }
  3067. else
  3068. {
  3069. currentStatus = 0; //OCPP Status: Available
  3070. }
  3071. }
  3072. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3073. {
  3074. currentStatus = 1; //OCPP Status: Preparing
  3075. }
  3076. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3077. {
  3078. currentStatus = 2; //OCPP Status: Charging
  3079. }
  3080. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3081. {
  3082. currentStatus = 5; //OCPP Status: Finishing
  3083. }
  3084. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3085. {
  3086. currentStatus = 4; //OCPP Status: SuspendedEV
  3087. }
  3088. 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
  3089. {
  3090. currentStatus = 7; //OCPP Status: Unavailable
  3091. }
  3092. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3093. {
  3094. currentStatus = 8; //OCPP Status: Faulted
  3095. }
  3096. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3097. {
  3098. currentStatus = 6; //OCPP Status: Reserved
  3099. }
  3100. }//end of the same index
  3101. }//end of for AC_QUANTITY
  3102. }
  3103. //it's option
  3104. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3105. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3106. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3107. random_uuid(guid);
  3108. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3109. , MESSAGE_TYPE_CALL
  3110. , guid
  3111. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3112. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3113. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3114. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3115. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3116. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3117. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3118. LWS_Send(message);
  3119. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3120. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3121. {
  3122. //DEBUG_ERROR("statusNotification mapitem pass");
  3123. result = PASS;
  3124. }
  3125. return result;
  3126. }
  3127. int sendStopTransactionRequest(int gun_index)
  3128. {
  3129. mtrace();
  3130. int result = FAIL;
  3131. //char message[1500]={0};
  3132. char guid[37]={0};
  3133. char tempdata[65]={0};
  3134. int tempIndex = 0;
  3135. //int idx_sample=0;
  3136. DEBUG_ERROR("sendStopTransactionRequest \n");
  3137. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3138. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3139. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3140. if(gunType[gun_index] == 'J')
  3141. {
  3142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3143. {
  3144. tempIndex = ((gun_index==2) ? 1: 0);
  3145. }
  3146. else
  3147. {
  3148. tempIndex = gun_index;
  3149. }
  3150. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3151. {
  3152. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3153. {
  3154. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3155. }
  3156. }// END OF CHAdeMO_QUANTITY
  3157. }
  3158. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3171. {
  3172. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3173. }
  3174. }// END OF CCS_QUANTITY
  3175. }
  3176. else if(gunType[gun_index] == 'G')
  3177. {
  3178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3179. {
  3180. tempIndex = ((gun_index==2) ? 1: 0);
  3181. }
  3182. else
  3183. {
  3184. tempIndex = gun_index;
  3185. }
  3186. for (int index = 0; index < GB_QUANTITY; index++)
  3187. {
  3188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3189. {
  3190. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3191. }
  3192. }// END OF GB_QUANTITY
  3193. }
  3194. else
  3195. {
  3196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3197. {
  3198. tempIndex = 2;
  3199. }
  3200. else
  3201. {
  3202. tempIndex = gun_index;
  3203. }
  3204. for (int index = 0; index < AC_QUANTITY; index++)
  3205. {
  3206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3207. {
  3208. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3209. }
  3210. }// END OF AC_QUANTITY
  3211. }
  3212. //====================================== Stop Transaction Time =====================================================
  3213. struct timeval tmnow;
  3214. struct tm *tm;
  3215. char buf[28];//, usec_buf[6];
  3216. gettimeofday(&tmnow, NULL);
  3217. time_t t;
  3218. t = time(NULL);
  3219. /*UTC time and date*/
  3220. tm = gmtime(&t);
  3221. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3223. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3224. random_uuid(guid);
  3225. /***********************************transactionData******************************************************/
  3226. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3228. //=================================
  3229. // Transaction_Begin
  3230. //=================================
  3231. //============================================ Energy.Active.Import.Interval ================================
  3232. //idx_sample=0;
  3233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3236. 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*/]);
  3237. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3238. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3239. {
  3240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3241. }
  3242. else
  3243. {
  3244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3245. }
  3246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3248. //=================================
  3249. // Transaction_End
  3250. //=================================
  3251. // ================================= Current.Import L1 ===============================================
  3252. //idx_sample=1;
  3253. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3254. if(gunType[gun_index] == 'J')
  3255. {
  3256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3257. {
  3258. tempIndex = ((gun_index==2) ? 1: 0);
  3259. }
  3260. else
  3261. {
  3262. tempIndex = gun_index;
  3263. }
  3264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3265. {
  3266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3267. {
  3268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3269. }
  3270. }// End of for CHAdeMO_QUANTITY
  3271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3272. }
  3273. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3274. {
  3275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3276. {
  3277. tempIndex = ((gun_index==2) ? 1: 0);
  3278. }
  3279. else
  3280. {
  3281. tempIndex = gun_index;
  3282. }
  3283. for (int index = 0; index < CCS_QUANTITY; index++)
  3284. {
  3285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3286. {
  3287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3288. }
  3289. }// End of for CCS_QUANTITY
  3290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3291. }
  3292. else if(gunType[gun_index] == 'G')
  3293. {
  3294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3295. {
  3296. tempIndex = ((gun_index==2) ? 1: 0);
  3297. }
  3298. else
  3299. {
  3300. tempIndex = gun_index;
  3301. }
  3302. for (int index = 0; index < GB_QUANTITY; index++)
  3303. {
  3304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3305. {
  3306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3307. }
  3308. }// End of for GB_QUANTITY
  3309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3310. }
  3311. else
  3312. {
  3313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3314. {
  3315. tempIndex = 2;
  3316. }
  3317. else
  3318. {
  3319. tempIndex = gun_index;
  3320. }
  3321. for (int index = 0; index < AC_QUANTITY; index++)
  3322. {
  3323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3324. {
  3325. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3326. }
  3327. }// End of for AC_QUANTITY
  3328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3329. }
  3330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3335. // ================================= Energy.Active.Import.Interval ==============================================
  3336. //idx_sample=2;
  3337. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3338. if(gunType[gun_index] == 'J')
  3339. {
  3340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3341. {
  3342. tempIndex = ((gun_index==2) ? 1: 0);
  3343. }
  3344. else
  3345. {
  3346. tempIndex = gun_index;
  3347. }
  3348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3349. {
  3350. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3351. {
  3352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3353. }
  3354. }// END OF CHAdeMO_QUANTITY
  3355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3356. }
  3357. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3358. {
  3359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3360. {
  3361. tempIndex = ((gun_index==2) ? 1: 0);
  3362. }
  3363. else
  3364. {
  3365. tempIndex = gun_index;
  3366. }
  3367. for (int index = 0; index < CCS_QUANTITY; index++)
  3368. {
  3369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3370. {
  3371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3372. }
  3373. }// END OF CCS_QUANTITY
  3374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3375. }
  3376. else if(gunType[gun_index] == 'G')
  3377. {
  3378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3379. {
  3380. tempIndex = ((gun_index==2) ? 1: 0);
  3381. }
  3382. else
  3383. {
  3384. tempIndex = gun_index;
  3385. }
  3386. for (int index = 0; index < GB_QUANTITY; index++)
  3387. {
  3388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3389. {
  3390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3391. }
  3392. }// END OF GB_QUANTITY
  3393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3394. }
  3395. else
  3396. {
  3397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3398. {
  3399. tempIndex = 2;
  3400. }
  3401. else
  3402. {
  3403. tempIndex = gun_index;
  3404. }
  3405. for (int index = 0; index < AC_QUANTITY; index++)
  3406. {
  3407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3408. {
  3409. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3410. }
  3411. }// END OF AC_QUANTITY
  3412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3413. }
  3414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3419. //=================================== Power.Active.Import ==================================================
  3420. //idx_sample=3;
  3421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3422. if(gunType[gun_index] == 'J')
  3423. {
  3424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3425. {
  3426. tempIndex = ((gun_index==2) ? 1: 0);
  3427. }
  3428. else
  3429. {
  3430. tempIndex = gun_index;
  3431. }
  3432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3433. {
  3434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3435. {
  3436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3437. }
  3438. } // End for CHAdeMO_QUANTITY
  3439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3440. }
  3441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3442. {
  3443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3444. {
  3445. tempIndex = ((gun_index==2) ? 1: 0);
  3446. }
  3447. else
  3448. {
  3449. tempIndex = gun_index;
  3450. }
  3451. for (int index = 0; index < CCS_QUANTITY; index++)
  3452. {
  3453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3454. {
  3455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3456. }
  3457. } // END for CCS_QUANTITY
  3458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3459. }
  3460. else if(gunType[gun_index] == 'G')
  3461. {
  3462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3463. {
  3464. tempIndex = ((gun_index==2) ? 1: 0);
  3465. }
  3466. else
  3467. {
  3468. tempIndex = gun_index;
  3469. }
  3470. for (int index = 0; index < GB_QUANTITY; index++)
  3471. {
  3472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3473. {
  3474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3475. }
  3476. }// END for GB_QUANTITY
  3477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3478. }
  3479. else
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3482. {
  3483. tempIndex = 2;
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < AC_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3492. {
  3493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3494. }
  3495. } // END for AC_QUANTITY
  3496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3497. }
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3503. //============================ Voltage L1 ====================================
  3504. //idx_sample=4;
  3505. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3506. if(gunType[gun_index] == 'J')
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3519. {
  3520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3521. }
  3522. } // END OF FOR CHAdeMO_QUANTITY
  3523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3524. }
  3525. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3526. {
  3527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3528. {
  3529. tempIndex = ((gun_index==2) ? 1: 0);
  3530. }
  3531. else
  3532. {
  3533. tempIndex = gun_index;
  3534. }
  3535. for (int index = 0; index < CCS_QUANTITY; index++)
  3536. {
  3537. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3538. {
  3539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3540. }
  3541. } // END OF FOR CCS_QUANTITY
  3542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3543. }
  3544. else if(gunType[gun_index] == 'G')
  3545. {
  3546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3547. {
  3548. tempIndex = ((gun_index==2) ? 1: 0);
  3549. }
  3550. else
  3551. {
  3552. tempIndex = gun_index;
  3553. }
  3554. for (int index = 0; index < GB_QUANTITY; index++)
  3555. {
  3556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3557. {
  3558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3559. }
  3560. } // END OF FOR GB_QUANTITY
  3561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3578. }
  3579. } // END OF FOR AC_QUANTITY
  3580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3581. }
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3587. //====================== SoC ================================
  3588. //idx_sample=5;
  3589. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3590. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  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. if(gunType[gun_index] == 'J')
  3601. {
  3602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3605. {
  3606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3607. }
  3608. }
  3609. }
  3610. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3611. {
  3612. for (int index = 0; index < CCS_QUANTITY; index++)
  3613. {
  3614. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3615. {
  3616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3617. }
  3618. }
  3619. }
  3620. else if(gunType[gun_index] == 'G')
  3621. {
  3622. for (int index = 0; index < GB_QUANTITY; index++)
  3623. {
  3624. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3625. {
  3626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3627. }
  3628. }
  3629. }
  3630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3636. } // END FOR DC CASE
  3637. // ================================= Current.Import L2 ===============================================
  3638. //idx_sample=6;
  3639. // AC 3 phse L2 current
  3640. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3641. {
  3642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3643. {
  3644. tempIndex = 2;
  3645. }
  3646. else
  3647. {
  3648. tempIndex = gun_index;
  3649. }
  3650. for (int index = 0; index < AC_QUANTITY; index++)
  3651. {
  3652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3653. {
  3654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3655. }
  3656. }// End of for AC_QUANTITY
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3658. }
  3659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3664. // ================================= Current.Import L3 ===============================================
  3665. //idx_sample=7;
  3666. // AC 3 phse L3 current
  3667. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3668. {
  3669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3670. {
  3671. tempIndex = 2;
  3672. }
  3673. else
  3674. {
  3675. tempIndex = gun_index;
  3676. }
  3677. for (int index = 0; index < AC_QUANTITY; index++)
  3678. {
  3679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3680. {
  3681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3682. }
  3683. }// End of for AC_QUANTITY
  3684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3685. }
  3686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3691. //============================ Voltage L2 ====================================
  3692. //idx_sample=8;
  3693. // AC 3 phse L2 voltage
  3694. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3695. {
  3696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3697. {
  3698. tempIndex = 2;
  3699. }
  3700. else
  3701. {
  3702. tempIndex = gun_index;
  3703. }
  3704. for (int index = 0; index < AC_QUANTITY; index++)
  3705. {
  3706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3707. {
  3708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3709. }
  3710. } // END OF FOR AC_QUANTITY
  3711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3712. }
  3713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3718. //============================ Voltage L3 ====================================
  3719. //idx_sample=8;
  3720. // AC 3 phse L3 voltage
  3721. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3722. {
  3723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3724. {
  3725. tempIndex = 2;
  3726. }
  3727. else
  3728. {
  3729. tempIndex = gun_index;
  3730. }
  3731. for (int index = 0; index < AC_QUANTITY; index++)
  3732. {
  3733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3734. {
  3735. 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
  3736. }
  3737. } // END OF FOR AC_QUANTITY
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3739. }
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3745. //================================================ Message create ====================================================
  3746. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3747. {
  3748. 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\"}]}]}]"
  3749. ,gun_index+1
  3750. ,MESSAGE_TYPE_CALL
  3751. ,guid
  3752. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3753. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3754. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3756. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3757. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3800. );
  3801. }
  3802. else
  3803. {
  3804. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3805. {
  3806. 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\"}]}]}]"
  3807. ,gun_index+1
  3808. ,MESSAGE_TYPE_CALL
  3809. ,guid
  3810. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3811. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3812. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3814. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3815. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3851. );
  3852. }
  3853. else
  3854. {
  3855. 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\"}]}]}]"
  3856. ,gun_index+1
  3857. ,MESSAGE_TYPE_CALL
  3858. ,guid
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3864. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  3928. );
  3929. }
  3930. }
  3931. #if 1 // for TempStopTransaction
  3932. //Delete TempStopTransaction
  3933. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3934. {
  3935. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3936. }
  3937. #endif
  3938. #if 1
  3939. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3940. if(hashmap_operation(0, guid, tempdata) == 1)
  3941. {
  3942. result = PASS;
  3943. DEBUG_INFO("StopTransaction mapitem pass\n");
  3944. }
  3945. #endif
  3946. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3947. /*
  3948. if(GetTransactionQueueNum() == 1)
  3949. {
  3950. LWS_Send(queuedata+2);
  3951. }*/
  3952. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3953. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  3954. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  3955. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3956. {
  3957. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3958. }
  3959. //for test
  3960. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3961. return result;
  3962. }
  3963. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  3964. {
  3965. mtrace();
  3966. int result = FAIL;
  3967. char guid[37]={0};
  3968. char tempdata[65]={0};
  3969. int tempIndex = 0;
  3970. DEBUG_INFO("sendMeterValuesRequest ...\n");
  3971. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  3972. /*
  3973. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3974. {
  3975. DEBUG_INFO("NOT SENT METER Vlaue\n");
  3976. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  3977. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  3978. return result;
  3979. }*/
  3980. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  3981. {
  3982. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3983. }
  3984. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3985. //set value
  3986. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  3987. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  3988. random_uuid(guid);
  3989. //UTC Date time
  3990. struct timeval tmnow;
  3991. struct tm *tm;
  3992. char buf[28];//, usec_buf[6];
  3993. gettimeofday(&tmnow, NULL);
  3994. time_t t;
  3995. t = time(NULL);
  3996. /*UTC time and date*/
  3997. tm = gmtime(&t);
  3998. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3999. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4000. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4001. //idx_sample=0;
  4002. //********************************(1)Current.Import L1************************************************/
  4003. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4004. if(gunType[gun_index] == 'J')
  4005. {
  4006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4007. {
  4008. tempIndex = ((gun_index==2) ? 1: 0);
  4009. }
  4010. else
  4011. {
  4012. tempIndex = gun_index;
  4013. }
  4014. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4015. {
  4016. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4017. {
  4018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4019. }
  4020. }
  4021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4022. }
  4023. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4024. {
  4025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4026. {
  4027. tempIndex = ((gun_index==2) ? 1: 0);
  4028. }
  4029. else
  4030. {
  4031. tempIndex = gun_index;
  4032. }
  4033. for (int index = 0; index < CCS_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4036. {
  4037. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4038. }
  4039. }
  4040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4041. }
  4042. else if(gunType[gun_index] == 'G')
  4043. {
  4044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4045. {
  4046. tempIndex = ((gun_index==2) ? 1: 0);
  4047. }
  4048. else
  4049. {
  4050. tempIndex = gun_index;
  4051. }
  4052. for (int index = 0; index < GB_QUANTITY; index++)
  4053. {
  4054. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4055. {
  4056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4057. }
  4058. }
  4059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4060. }
  4061. else
  4062. {
  4063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4064. {
  4065. tempIndex = 2;
  4066. }
  4067. else
  4068. {
  4069. tempIndex = gun_index;
  4070. }
  4071. for (int index = 0; index < AC_QUANTITY; index++)
  4072. {
  4073. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4074. {
  4075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4076. }
  4077. }
  4078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4079. }
  4080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4083. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4085. //idx_sample=1;
  4086. //********************************(2)Energy.Active.Import.Register ************************************************/
  4087. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4088. if(gunType[gun_index] == 'J')
  4089. {
  4090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4091. {
  4092. tempIndex = ((gun_index==2) ? 1: 0);
  4093. }
  4094. else
  4095. {
  4096. tempIndex = gun_index;
  4097. }
  4098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4099. {
  4100. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4101. {
  4102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4103. }
  4104. }
  4105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4106. }
  4107. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4108. {
  4109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4110. {
  4111. tempIndex = ((gun_index==2) ? 1: 0);
  4112. }
  4113. else
  4114. {
  4115. tempIndex = gun_index;
  4116. }
  4117. for (int index = 0; index < CCS_QUANTITY; index++)
  4118. {
  4119. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4120. {
  4121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4122. }
  4123. }
  4124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4125. }
  4126. else if(gunType[gun_index] == 'G')
  4127. {
  4128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4129. {
  4130. tempIndex = ((gun_index==2) ? 1: 0);
  4131. }
  4132. else
  4133. {
  4134. tempIndex = gun_index;
  4135. }
  4136. for (int index = 0; index < GB_QUANTITY; index++)
  4137. {
  4138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4139. {
  4140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4141. }
  4142. }
  4143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4144. }
  4145. else
  4146. {
  4147. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4148. {
  4149. tempIndex = 2;
  4150. }
  4151. else
  4152. {
  4153. tempIndex = gun_index;
  4154. }
  4155. for (int index = 0; index < AC_QUANTITY; index++)
  4156. {
  4157. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4158. {
  4159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4160. }
  4161. }
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4163. }
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4165. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4169. //idx_sample=2;
  4170. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4171. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4172. if(gunType[gun_index] == 'J')
  4173. {
  4174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4175. {
  4176. tempIndex = ((gun_index==2) ? 1: 0);
  4177. }
  4178. else
  4179. {
  4180. tempIndex = gun_index;
  4181. }
  4182. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4183. {
  4184. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4185. {
  4186. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4187. }
  4188. } // END OF FOR CHAdeMO_QUANTITY
  4189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4190. }
  4191. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4192. {
  4193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4194. {
  4195. tempIndex = ((gun_index==2) ? 1: 0);
  4196. }
  4197. else
  4198. {
  4199. tempIndex = gun_index;
  4200. }
  4201. for (int index = 0; index < CCS_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4204. {
  4205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4206. }
  4207. } // END OF CCS_QUANTITY
  4208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4209. }
  4210. else if(gunType[gun_index] == 'G')
  4211. {
  4212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4213. {
  4214. tempIndex = ((gun_index==2) ? 1: 0);
  4215. }
  4216. else
  4217. {
  4218. tempIndex = gun_index;
  4219. }
  4220. for (int index = 0; index < GB_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4223. {
  4224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4225. }
  4226. } // END OF GB_QUANTITY
  4227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4228. }
  4229. else
  4230. {
  4231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4232. {
  4233. tempIndex = 2;
  4234. }
  4235. else
  4236. {
  4237. tempIndex = gun_index;
  4238. }
  4239. for (int index = 0; index < AC_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4242. {
  4243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4244. }
  4245. }
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4247. }
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4253. //idx_sample=3;
  4254. //********************************(4)Power.Active.Import************************************************/
  4255. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4256. if(gunType[gun_index] == 'J')
  4257. {
  4258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4259. {
  4260. tempIndex = ((gun_index==2) ? 1: 0);
  4261. }
  4262. else
  4263. {
  4264. tempIndex = gun_index;
  4265. }
  4266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4269. {
  4270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4271. }
  4272. } // END OF FOR
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4274. }
  4275. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4276. {
  4277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4278. {
  4279. tempIndex = ((gun_index==2) ? 1: 0);
  4280. }
  4281. else
  4282. {
  4283. tempIndex = gun_index;
  4284. }
  4285. for (int index = 0; index < CCS_QUANTITY; index++)
  4286. {
  4287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4288. {
  4289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4290. }
  4291. }
  4292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4293. }
  4294. else if(gunType[gun_index] == 'G')
  4295. {
  4296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4297. {
  4298. tempIndex = ((gun_index==2) ? 1: 0);
  4299. }
  4300. else
  4301. {
  4302. tempIndex = gun_index;
  4303. }
  4304. for (int index = 0; index < GB_QUANTITY; index++)
  4305. {
  4306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4307. {
  4308. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4310. }
  4311. }
  4312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4313. }
  4314. else
  4315. {
  4316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4317. {
  4318. tempIndex = 2;
  4319. }
  4320. else
  4321. {
  4322. tempIndex = gun_index;
  4323. }
  4324. for (int index = 0; index < AC_QUANTITY; index++)
  4325. {
  4326. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4327. {
  4328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4329. }
  4330. }
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4332. }
  4333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4338. //idx_sample=4;
  4339. //***********************************************(5)VOLTAGE L1******************************************************/
  4340. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4341. if(gunType[gun_index] == 'J')
  4342. {
  4343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4344. {
  4345. tempIndex = ((gun_index==2) ? 1: 0);
  4346. }
  4347. else
  4348. {
  4349. tempIndex = gun_index;
  4350. }
  4351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4352. {
  4353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4354. {
  4355. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4356. }
  4357. }
  4358. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4359. }
  4360. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CCS_QUANTITY; index++)
  4371. {
  4372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4373. {
  4374. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4375. }
  4376. }
  4377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4378. }
  4379. else if(gunType[gun_index] == 'G')
  4380. {
  4381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4382. {
  4383. tempIndex = ((gun_index==2) ? 1: 0);
  4384. }
  4385. else
  4386. {
  4387. tempIndex = gun_index;
  4388. }
  4389. for (int index = 0; index < GB_QUANTITY; index++)
  4390. {
  4391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4392. {
  4393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4394. }
  4395. }
  4396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4397. }
  4398. else
  4399. {
  4400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4401. {
  4402. tempIndex = 2;
  4403. }
  4404. else
  4405. {
  4406. tempIndex = gun_index;
  4407. }
  4408. for (int index = 0; index < AC_QUANTITY; index++)
  4409. {
  4410. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4411. {
  4412. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4413. }
  4414. }
  4415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4416. }
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4422. //***********************************************(6)SOC******************************************************/
  4423. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4424. {
  4425. //idx_sample=5;
  4426. //sampledValue = NULL;
  4427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4428. {
  4429. tempIndex = ((gun_index==2) ? 1: 0);
  4430. }
  4431. else
  4432. {
  4433. tempIndex = gun_index;
  4434. }
  4435. if(gunType[gun_index] == 'J')
  4436. {
  4437. //tempIndex = ((gun_index==2) ? 1: 0);
  4438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4439. {
  4440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4441. {
  4442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4443. }
  4444. }
  4445. }
  4446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4447. {
  4448. //tempIndex = ((gun_index==2) ? 1: 0);
  4449. for (int index = 0; index < CCS_QUANTITY; index++)
  4450. {
  4451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4452. {
  4453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4454. }
  4455. }
  4456. }
  4457. else if(gunType[gun_index] == 'G')
  4458. {
  4459. //tempIndex = ((gun_index==2) ? 1: 0);
  4460. for (int index = 0; index < GB_QUANTITY; index++)
  4461. {
  4462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4463. {
  4464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4465. }
  4466. }
  4467. }
  4468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4474. }
  4475. //********************************(7)Current.Import L2************************************************/
  4476. // Only for AC 3 phase
  4477. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4480. {
  4481. tempIndex = 2;
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < AC_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4490. {
  4491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4492. }
  4493. }
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4495. }
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4501. //********************************(8)Current.Import L3************************************************/
  4502. // Only for AC 3 phase
  4503. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4504. {
  4505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4506. {
  4507. tempIndex = 2;
  4508. }
  4509. else
  4510. {
  4511. tempIndex = gun_index;
  4512. }
  4513. for (int index = 0; index < AC_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4516. {
  4517. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4518. }
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4521. }
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4527. //***********************************************(9)VOLTAGE L2******************************************************/
  4528. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4531. {
  4532. tempIndex = 2;
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < AC_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4543. }
  4544. }
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4546. }
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4552. //***********************************************(10)VOLTAGE L3******************************************************/
  4553. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4554. {
  4555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4556. {
  4557. tempIndex = 2;
  4558. }
  4559. else
  4560. {
  4561. tempIndex = gun_index;
  4562. }
  4563. for (int index = 0; index < AC_QUANTITY; index++)
  4564. {
  4565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4566. {
  4567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4568. }
  4569. }
  4570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4571. }
  4572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4577. // Message create ====================================================================================================
  4578. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4579. {
  4580. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4581. ,gun_index + 1
  4582. ,MESSAGE_TYPE_CALL
  4583. ,guid
  4584. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4585. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4586. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4606. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4607. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4608. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4609. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4610. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4611. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4612. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4613. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4614. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4615. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4629. );
  4630. }
  4631. else
  4632. {
  4633. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4634. {
  4635. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4636. ,gun_index + 1
  4637. ,MESSAGE_TYPE_CALL
  4638. ,guid
  4639. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4640. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4641. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4677. );
  4678. }
  4679. else
  4680. {
  4681. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4682. ,gun_index + 1
  4683. ,MESSAGE_TYPE_CALL
  4684. ,guid
  4685. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4686. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4687. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4751. );
  4752. }
  4753. }
  4754. // Put request guid to hash map
  4755. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4756. 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*/)
  4757. {
  4758. result = PASS;
  4759. DEBUG_INFO("MeterValues mapitem pass\n");
  4760. }
  4761. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4762. /*
  4763. if(GetTransactionQueueNum() == 1)
  4764. {
  4765. LWS_Send(queuedata +2);
  4766. }*/
  4767. return result;
  4768. }
  4769. //==========================================
  4770. // send confirm routine
  4771. //==========================================
  4772. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4773. {
  4774. mtrace();
  4775. int result = FAIL;
  4776. char message[100]={0};
  4777. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4778. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4779. LWS_Send(message);
  4780. result = TRUE;
  4781. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4782. return result;
  4783. }
  4784. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4785. {
  4786. mtrace();
  4787. int result = FAIL;
  4788. char message[100]={0};
  4789. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4790. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4791. LWS_Send(message);
  4792. result = TRUE;
  4793. return result;
  4794. }
  4795. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4796. {
  4797. mtrace();
  4798. int result = FAIL;
  4799. char message[100]={0};
  4800. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4801. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4802. LWS_Send(message);
  4803. result = TRUE;
  4804. return result;
  4805. }
  4806. int sendClearCacheConfirmation(char *uuid,char *payload)
  4807. {
  4808. mtrace();
  4809. int result = FAIL;
  4810. char message[500]={0};
  4811. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4812. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4813. LWS_Send(message);
  4814. return result;
  4815. }
  4816. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4817. {
  4818. mtrace();
  4819. int result = FAIL;
  4820. char message[500]={0};
  4821. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4822. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4823. LWS_Send(message);
  4824. return result;
  4825. }
  4826. int sendDataTransferConfirmation(char *uuid,char *payload)
  4827. {
  4828. mtrace();
  4829. char statusStr[20]={0};
  4830. char dataStr[10]={0};
  4831. char sstr[20]={0};
  4832. int c = 0;
  4833. char *loc;
  4834. int result = FAIL;
  4835. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4836. /**********************status**************************/
  4837. loc = strstr(payload, "status");
  4838. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4839. c = 0;
  4840. while (loc[3+strlen("status")+c] != '\"')
  4841. {
  4842. sstr[c] = loc[3+strlen("status")+c];
  4843. c++;
  4844. }
  4845. sstr[c] = '\0';
  4846. strcpy(statusStr, sstr);
  4847. /**********************data**************************/
  4848. loc = strstr(payload, "data");
  4849. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4850. c = 0;
  4851. while (loc[3+strlen("data")+c] != '\"')
  4852. {
  4853. sstr[c] = loc[3+strlen("data")+c];
  4854. c++;
  4855. }
  4856. sstr[c] = '\0';
  4857. strcpy(dataStr, sstr);
  4858. return result;
  4859. }
  4860. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4861. {
  4862. mtrace();
  4863. int result = FAIL;
  4864. char message[1000]={0};
  4865. int CompositeScheduleIndex = 0;
  4866. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4867. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4868. if(nPeriod == 0)
  4869. {
  4870. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4871. {
  4872. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4873. ,MESSAGE_TYPE_CALLRESULT
  4874. ,uuid
  4875. ,payload
  4876. ,connectorIdInt);
  4877. }
  4878. else
  4879. {
  4880. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4881. ,MESSAGE_TYPE_CALLRESULT
  4882. ,uuid
  4883. ,payload
  4884. ,connectorIdInt
  4885. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4886. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4887. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4888. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4889. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4890. }
  4891. }
  4892. else
  4893. {
  4894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4895. ,MESSAGE_TYPE_CALLRESULT
  4896. ,uuid
  4897. ,payload
  4898. ,connectorIdInt
  4899. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4900. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4901. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4902. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4903. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4904. {
  4905. if (idx_sample == 0)
  4906. {
  4907. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4908. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4909. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4910. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4911. }
  4912. else
  4913. {
  4914. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4915. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4916. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4917. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4918. }
  4919. }
  4920. sprintf(message + strlen(message), "]}}]");
  4921. }
  4922. LWS_Send(message);
  4923. result = TRUE;
  4924. return result;
  4925. }
  4926. int sendGetConfigurationConfirmation(char *uuid)
  4927. {
  4928. mtrace();
  4929. int result = FAIL;
  4930. int MaxKeySupported = 0;
  4931. int sentConfigurationNumber= 0;
  4932. int sentunConfigurationNumber= 0;
  4933. char message[4000]={0};
  4934. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4935. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4936. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4937. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4938. ,MESSAGE_TYPE_CALLRESULT
  4939. ,uuid );
  4940. //configuration key
  4941. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4942. {
  4943. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4944. {
  4945. if (sentConfigurationNumber == 0)
  4946. {
  4947. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4948. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4949. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4950. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4951. }
  4952. else
  4953. {
  4954. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4955. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4956. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4957. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4958. }
  4959. sentConfigurationNumber = sentConfigurationNumber + 1;
  4960. }
  4961. }
  4962. sprintf(message + strlen(message), "]");
  4963. if(UnknownKeynum != 0)
  4964. {
  4965. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4966. //unkown key
  4967. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4968. {
  4969. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4970. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4971. if(sentunConfigurationNumber == 0)
  4972. {
  4973. sprintf(message + strlen(message), "\"%s\""
  4974. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4975. }
  4976. else
  4977. {
  4978. sprintf(message + strlen(message), ",\"%s\""
  4979. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4980. }
  4981. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4982. }
  4983. sprintf(message + strlen(message), "]");
  4984. }
  4985. sprintf(message + strlen(message), "}]");
  4986. LWS_Send(message);
  4987. return result;
  4988. }
  4989. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4990. {
  4991. mtrace();
  4992. int result = FAIL;
  4993. char message[400]={0};
  4994. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4995. if(strcmp(payload,"")==0)
  4996. {
  4997. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4998. }
  4999. else
  5000. {
  5001. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5002. }
  5003. LWS_Send(message);
  5004. result = TRUE;
  5005. return result;
  5006. }
  5007. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5008. {
  5009. mtrace();
  5010. int result = FAIL;
  5011. char message[80]={0};
  5012. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5013. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5014. LWS_Send(message);
  5015. result = TRUE;
  5016. return result;
  5017. }
  5018. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5019. {
  5020. mtrace();
  5021. int result = FAIL;
  5022. char message[80]={0};
  5023. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5024. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5025. LWS_Send(message);
  5026. result = TRUE;
  5027. return result;
  5028. }
  5029. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5030. {
  5031. mtrace();
  5032. int result = FAIL;
  5033. char message[80]={0};
  5034. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5035. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5036. LWS_Send(message);
  5037. result = TRUE;
  5038. return result;
  5039. }
  5040. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5041. {
  5042. mtrace();
  5043. int result = FAIL;
  5044. char message[80]={0};
  5045. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5046. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5047. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5048. LWS_Send(message);
  5049. result = TRUE;
  5050. return result;
  5051. }
  5052. int sendResetConfirmation(char *uuid,char *payload)
  5053. {
  5054. mtrace();
  5055. int result = FAIL;
  5056. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5057. char message[80]={0};
  5058. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5059. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5060. LWS_Send(message);
  5061. result = TRUE;
  5062. return result;
  5063. }
  5064. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5065. {
  5066. mtrace();
  5067. int result = FAIL;
  5068. char message[500]={0};
  5069. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5070. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5071. LWS_Send(message);
  5072. result = TRUE;
  5073. return result;
  5074. }
  5075. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5076. {
  5077. mtrace();
  5078. int result = FAIL;
  5079. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5080. char message[80]={0};
  5081. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5082. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5083. LWS_Send(message);
  5084. result = TRUE;
  5085. return result;
  5086. }
  5087. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5088. {
  5089. mtrace();
  5090. int result = FAIL;
  5091. char message[80]={0};
  5092. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5093. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5094. LWS_Send(message);
  5095. result = TRUE;
  5096. return result;
  5097. }
  5098. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5099. {
  5100. mtrace();
  5101. int result = FAIL;
  5102. char message[80]={0};
  5103. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5104. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5105. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5106. LWS_Send(message);
  5107. result = TRUE;
  5108. return result;
  5109. }
  5110. int sendUpdateFirmwareConfirmation(char *uuid)
  5111. {
  5112. mtrace();
  5113. int result = FAIL;
  5114. char message[60]={0};
  5115. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5116. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5117. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5118. LWS_Send(message);
  5119. result = TRUE;
  5120. return result;
  5121. }
  5122. //==========================================
  5123. // send CallError routine
  5124. //==========================================
  5125. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5126. {
  5127. mtrace();
  5128. char message[220]={0};
  5129. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5130. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5131. LWS_Send(message);
  5132. }
  5133. //==========================================
  5134. // Handle server request routine Start
  5135. //==========================================
  5136. int handleCancelReservationRequest(char *uuid, char *payload)
  5137. {
  5138. mtrace();
  5139. int result = FAIL;
  5140. int gunNO = 0;
  5141. int reservationIdInt =0;
  5142. char comfirmstr[20];
  5143. DEBUG_INFO("handleCancelReservationRequest...\n");
  5144. json_object *CancelReservation;
  5145. CancelReservation = json_tokener_parse(payload);
  5146. if(!is_error(CancelReservation))
  5147. {
  5148. // Required data
  5149. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5150. }
  5151. json_object_put(CancelReservation);
  5152. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5153. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5154. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5155. //check Transaction active
  5156. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5157. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5158. {
  5159. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5160. {
  5161. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5162. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5163. if(gunType[2] == 'J')
  5164. {
  5165. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5166. }
  5167. else
  5168. {
  5169. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5170. }
  5171. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5172. goto end;
  5173. }
  5174. }
  5175. for (int index = 0; index < CCS_QUANTITY; index++)
  5176. {
  5177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5178. {
  5179. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5180. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5181. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5182. {
  5183. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5184. }
  5185. else
  5186. {
  5187. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5188. }
  5189. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5190. goto end;
  5191. }
  5192. }
  5193. for (int index = 0; index < GB_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5196. {
  5197. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5198. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5199. if(gunType[2] == 'G')
  5200. {
  5201. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5202. }
  5203. else
  5204. {
  5205. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5206. }
  5207. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5208. goto end;
  5209. }
  5210. }
  5211. for (int index = 0; index < AC_QUANTITY; index++)
  5212. {
  5213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5214. {
  5215. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5216. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5217. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5218. {
  5219. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5220. }
  5221. else
  5222. {
  5223. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5224. }
  5225. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5226. goto end;
  5227. }
  5228. }
  5229. //The reservationId does NOT match the reservationId
  5230. sendCancelReservationConfirmation(uuid, comfirmstr);
  5231. end:
  5232. // Fill in ocpp packet uuid
  5233. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5234. return result;
  5235. }
  5236. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5237. {
  5238. mtrace();
  5239. int result = FAIL;
  5240. int gunIndex = 0;
  5241. char typeStr[16]={0};
  5242. char comfirmstr[20];
  5243. int specificId = FALSE;
  5244. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5245. json_object *ChangeAvailability;
  5246. ChangeAvailability = json_tokener_parse(payload);
  5247. if(!is_error(ChangeAvailability))
  5248. {
  5249. // Required data
  5250. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5251. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5252. }
  5253. json_object_put(ChangeAvailability);
  5254. if(gunIndex != 0)
  5255. {
  5256. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5257. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5258. }
  5259. else
  5260. {
  5261. for(int i=0; i < gunTotalNumber; i++)
  5262. {
  5263. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5264. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5265. }
  5266. }
  5267. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5269. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5270. {
  5271. specificId = TRUE;
  5272. }
  5273. if(specificId == FALSE)
  5274. goto end;
  5275. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5276. {
  5277. //----------------------gunIndex is 0 ------------------------------------------------//
  5278. if(gunIndex == 0)
  5279. {
  5280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5281. {
  5282. for(int i=0; i < gunTotalNumber; i++)
  5283. {
  5284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5285. {
  5286. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5287. {
  5288. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5289. {
  5290. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5291. goto end;
  5292. }
  5293. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5294. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5295. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5296. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5297. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5298. {
  5299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5300. goto end;
  5301. }
  5302. }
  5303. }//END FOR CHAdeMO_QUANTITY
  5304. for (int index = 0; index < CCS_QUANTITY; index++)
  5305. {
  5306. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5307. {
  5308. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5309. {
  5310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5311. goto end;
  5312. }
  5313. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5314. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5315. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5316. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5317. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5318. {
  5319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5320. goto end;
  5321. }
  5322. }
  5323. }//END FOR CCS_QUANTITY
  5324. for (int index = 0; index < GB_QUANTITY; index++)
  5325. {
  5326. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5327. {
  5328. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5329. {
  5330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5331. goto end;
  5332. }
  5333. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5334. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5335. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5336. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5337. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5338. {
  5339. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5340. goto end;
  5341. }
  5342. }
  5343. }// END FOR GB_QUANTITY
  5344. for (int index = 0; index < AC_QUANTITY; index++)
  5345. {
  5346. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5347. {
  5348. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5349. {
  5350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5351. goto end;
  5352. }
  5353. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5354. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5355. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5356. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5357. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5358. {
  5359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5360. goto end;
  5361. }
  5362. }
  5363. }//END FOR AC_QUANTITY
  5364. }// END FOR gunTotalNumber
  5365. }
  5366. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5367. {
  5368. for(int i=0; i < gunTotalNumber; i++)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5371. {
  5372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5373. goto end;
  5374. }
  5375. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5377. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5379. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5380. {
  5381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5382. goto end;
  5383. }
  5384. }
  5385. }
  5386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5387. goto end;
  5388. }
  5389. //----------------------gunIndex is not 0 ------------------------------------------------//
  5390. //check Transaction active
  5391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5392. {
  5393. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5394. {
  5395. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5396. {
  5397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5398. goto end;
  5399. }
  5400. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5401. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5402. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5403. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5404. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5405. {
  5406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5407. goto end;
  5408. }
  5409. else
  5410. {
  5411. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5413. goto end;
  5414. }
  5415. }
  5416. }//END FOR CHAdeMO_QUANTITY
  5417. for (int index = 0; index < CCS_QUANTITY; index++)
  5418. {
  5419. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5420. {
  5421. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5422. {
  5423. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5424. goto end;
  5425. }
  5426. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5427. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5428. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5431. {
  5432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5433. goto end;
  5434. }
  5435. else
  5436. {
  5437. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5439. goto end;
  5440. }
  5441. }
  5442. }//END FOR CCS_QUANTITY
  5443. for (int index = 0; index < GB_QUANTITY; index++)
  5444. {
  5445. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5446. {
  5447. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5448. {
  5449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5450. goto end;
  5451. }
  5452. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5456. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5457. {
  5458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5459. goto end;
  5460. }
  5461. else
  5462. {
  5463. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5465. goto end;
  5466. }
  5467. }
  5468. }// END FOR GB_QUANTITY
  5469. for (int index = 0; index < AC_QUANTITY; index++)
  5470. {
  5471. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5472. {
  5473. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5474. {
  5475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5476. goto end;
  5477. }
  5478. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5481. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5482. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5483. {
  5484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5485. goto end;
  5486. }
  5487. else
  5488. {
  5489. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5491. goto end;
  5492. }
  5493. }
  5494. }//END FOR AC_QUANTITY
  5495. }//END FOR AvailabilityTypeStr[Inoperative]
  5496. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5497. {
  5498. //----------------------gunIndex is 0 ------------------------------------------------//
  5499. if(gunIndex == 0)
  5500. {
  5501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5502. {
  5503. for(int i=0; i < gunTotalNumber; i++)
  5504. {
  5505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5506. {
  5507. 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
  5508. {
  5509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5510. goto end;
  5511. }
  5512. }//END FOR CHAdeMO_QUANTITY
  5513. for (int index = 0; index < CCS_QUANTITY; index++)
  5514. {
  5515. 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
  5516. {
  5517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5518. goto end;
  5519. }
  5520. }//END FOR CCS_QUANTITY
  5521. for (int index = 0; index < GB_QUANTITY; index++)
  5522. {
  5523. 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
  5524. {
  5525. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5527. goto end;
  5528. }
  5529. }// END FOR GB_QUANTITY
  5530. for (int index = 0; index < AC_QUANTITY; index++)
  5531. {
  5532. 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
  5533. {
  5534. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5535. goto end;
  5536. }
  5537. }//END FOR CHAdeMO_QUANTITY
  5538. }// END FOR gunTotalNumber
  5539. }
  5540. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5541. {
  5542. for(int i=0; i < gunTotalNumber; i++)
  5543. {
  5544. for (int index = 0; index < AC_QUANTITY; index++)
  5545. {
  5546. 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
  5547. {
  5548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5549. goto end;
  5550. }
  5551. }//END FOR CHAdeMO_QUANTITY
  5552. } // END FOR gunTotalNumber
  5553. }
  5554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5555. goto end;
  5556. }
  5557. //----------------------gunIndex is not 0 ------------------------------------------------//
  5558. //check Transaction active
  5559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5560. {
  5561. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5562. {
  5563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5564. goto end;
  5565. }
  5566. }//END FOR CHAdeMO_QUANTITY
  5567. for (int index = 0; index < CCS_QUANTITY; index++)
  5568. {
  5569. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5570. {
  5571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5572. goto end;
  5573. }
  5574. }//END FOR CCS_QUANTITY
  5575. for (int index = 0; index < GB_QUANTITY; index++)
  5576. {
  5577. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5578. {
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5580. goto end;
  5581. }
  5582. }// END FOR GB_QUANTITY
  5583. for (int index = 0; index < AC_QUANTITY; index++)
  5584. {
  5585. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5586. {
  5587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5588. goto end;
  5589. }
  5590. }//END FOR AC_QUANTITY
  5591. }//END FOR AvailabilityTypeStr[Operative]
  5592. end:
  5593. if(gunIndex != 0)
  5594. {
  5595. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5596. }
  5597. else
  5598. {
  5599. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5600. }
  5601. if(gunIndex != 0)
  5602. {
  5603. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5604. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5605. }
  5606. else
  5607. {
  5608. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5609. {
  5610. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5611. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5612. }
  5613. }
  5614. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5615. return result;
  5616. }
  5617. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5618. {
  5619. mtrace();
  5620. int result = FAIL;
  5621. char keystr[40]={0};
  5622. char valuestr[100]={0};
  5623. char comfirmstr[20]={0};
  5624. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5625. json_object *ChangeConfiguration;
  5626. ChangeConfiguration = json_tokener_parse(payload);
  5627. if(!is_error(ChangeConfiguration))
  5628. {
  5629. // Required data
  5630. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5631. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5632. }
  5633. json_object_put(ChangeConfiguration);
  5634. if((uuid==NULL) || (payload ==NULL) )
  5635. {
  5636. DEBUG_ERROR("Payload is null\n");
  5637. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5638. }
  5639. else
  5640. {
  5641. int status = setKeyValue(keystr, valuestr);
  5642. switch(status)
  5643. {
  5644. case ConfigurationStatus_Accepted:
  5645. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5646. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5647. StoreConfigurationTable();
  5648. break;
  5649. case ConfigurationStatus_Rejected:
  5650. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5651. break;
  5652. case RebootRequired:
  5653. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5654. StoreConfigurationTable();
  5655. break;
  5656. case NotSupported:
  5657. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5658. break;
  5659. default:
  5660. break;
  5661. }
  5662. }
  5663. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5664. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5665. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5666. {
  5667. ChageWebSocketPingInterval(atoi(valuestr));
  5668. }
  5669. return result;
  5670. }
  5671. int handleClearCacheRequest(char *uuid, char *payload)
  5672. {
  5673. mtrace();
  5674. int result = FAIL;
  5675. char comfirmstr[20];
  5676. int fd;
  5677. char rmFileCmd[100]={0};
  5678. struct stat stats;
  5679. DEBUG_INFO("handleClearCacheRequest...\n");
  5680. stat("/Storage/OCPP", &stats);
  5681. // Check for directory existence
  5682. if (S_ISDIR(stats.st_mode) == 1)
  5683. {}
  5684. else
  5685. {
  5686. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5687. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5688. system(rmFileCmd);
  5689. }
  5690. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5691. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5692. {
  5693. DEBUG_INFO("AuthorizationCache file exist.\n");
  5694. }
  5695. else
  5696. {
  5697. DEBUG_INFO("AuthorizationCache file not exist\n");
  5698. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5699. if(log == NULL)
  5700. {
  5701. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5702. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5703. goto end;
  5704. }
  5705. else
  5706. {
  5707. fclose(log);
  5708. }
  5709. }
  5710. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5711. {
  5712. DEBUG_INFO("open AuthorizationCache file failed\n");
  5713. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5714. }
  5715. else
  5716. {
  5717. DEBUG_INFO("open AuthorizationCache file successful\n");
  5718. ftruncate(fd,0);
  5719. lseek(fd,0,SEEK_SET);
  5720. close(fd);
  5721. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5722. }
  5723. end:
  5724. sendClearCacheConfirmation(uuid, comfirmstr);
  5725. return result;
  5726. }
  5727. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5728. {
  5729. mtrace();
  5730. int result = FAIL;
  5731. int resultRename;
  5732. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5733. char chargingProfilePurposeStr[26]={0};
  5734. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5735. char tempchargingProfilePurposeStr[26]={0};
  5736. char sstr[160]={0};
  5737. char str[100]={0};
  5738. int c = 0;
  5739. char *loc;
  5740. char fname[200]={0};
  5741. char comfirmstr[20]={0};
  5742. char word[1600]={0};
  5743. int clearflag = FALSE;
  5744. int chargingProfileIdIsNULL = FALSE;
  5745. int connectorIsNULL = FALSE;
  5746. int chargingProfilePurposeIsNULL = FALSE;
  5747. int stackLevelIsNULL = FALSE;
  5748. //int GotoEnd = FALSE;
  5749. FILE *fptr1, *fptr2;
  5750. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5751. int n_chargingProfile=0;
  5752. int isEmptyFile = FALSE;
  5753. char sLineWord[1600]={0};
  5754. char chargingProfiles[10][100]={0};
  5755. int ChargeProfileCount = 0;
  5756. char ch;
  5757. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5758. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5759. json_object *ClearChargingProfile;
  5760. ClearChargingProfile = json_tokener_parse(payload);
  5761. if(!is_error(ClearChargingProfile))
  5762. {
  5763. // Optional data
  5764. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5765. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5766. else
  5767. chargingProfileIdIsNULL = TRUE;
  5768. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5769. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5770. else
  5771. connectorIsNULL = TRUE;
  5772. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5773. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5774. else
  5775. chargingProfilePurposeIsNULL = TRUE;
  5776. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5777. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5778. else
  5779. stackLevelIsNULL = TRUE;
  5780. }
  5781. json_object_put(ClearChargingProfile);
  5782. if(connectorIsNULL == FALSE)
  5783. {
  5784. switch(connectorIdInt)
  5785. {
  5786. case 0:
  5787. if(chargingProfilePurposeIsNULL == TRUE)
  5788. {
  5789. int l = 0;
  5790. strcpy(fname, ChargePointMaxProfile_JSON);
  5791. if((access(fname,F_OK))!=-1)
  5792. {
  5793. strcpy(chargingProfiles[l], fname);
  5794. l = l + 1;
  5795. }
  5796. strcpy(fname, TxDefaultProfile_0_JSON);
  5797. if((access(fname,F_OK))!=-1)
  5798. {
  5799. strcpy(chargingProfiles[l], fname);
  5800. l = l + 1;
  5801. }
  5802. ChargeProfileCount = l;
  5803. }
  5804. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5805. {
  5806. strcpy(fname, ChargePointMaxProfile_JSON);
  5807. if((access(fname,F_OK))!=-1)
  5808. {
  5809. strcpy(chargingProfiles[0], fname);
  5810. ChargeProfileCount = 1;
  5811. }
  5812. }
  5813. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5814. {
  5815. strcpy(fname, TxDefaultProfile_0_JSON);
  5816. if((access(fname,F_OK))!=-1)
  5817. {
  5818. strcpy(chargingProfiles[0], fname);
  5819. ChargeProfileCount = 1;
  5820. }
  5821. }
  5822. break;
  5823. default:
  5824. if(chargingProfilePurposeIsNULL == TRUE)
  5825. {
  5826. int m = 0;
  5827. memset(fname, 0, ARRAY_SIZE(fname));
  5828. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5829. if((access(fname,F_OK))!=-1)
  5830. {
  5831. strcpy(chargingProfiles[m], fname);
  5832. m = m + 1;
  5833. }
  5834. memset(fname, 0, ARRAY_SIZE(fname));
  5835. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5836. if((access(fname,F_OK))!=-1)
  5837. {
  5838. strcpy(chargingProfiles[m], fname);
  5839. m = m + 1;
  5840. }
  5841. ChargeProfileCount = m;
  5842. }
  5843. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5844. {
  5845. //strcpy(fname, TxDefaultProfile_1_JSON);
  5846. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5847. if((access(fname,F_OK))!=-1)
  5848. {
  5849. strcpy(chargingProfiles[0], fname);
  5850. ChargeProfileCount = 1;
  5851. }
  5852. }
  5853. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5854. {
  5855. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5856. if((access(fname,F_OK))!=-1)
  5857. {
  5858. strcpy(chargingProfiles[0], fname);
  5859. ChargeProfileCount = 1;
  5860. }
  5861. //strcpy(fname, TxProfile_1_JSON);
  5862. }
  5863. //strcpy(fname, ChargePointMaxProfile_JSON );
  5864. break;
  5865. }
  5866. }
  5867. else // Check all Charging Profiles
  5868. {
  5869. int i = 0;
  5870. char fnametemp[200]={0};
  5871. ChargeProfileCount = 0;
  5872. //Check ChargePointMaxProfile.json exit
  5873. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5874. {
  5875. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5876. i = i + 1;
  5877. }
  5878. //Check TxDefaultProfile_0.json exit
  5879. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5880. {
  5881. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5882. i = i + 1;
  5883. }
  5884. //Check TxDefaultProfile_%d.json
  5885. for(int j=1; j <= gunTotalNumber; j++)
  5886. {
  5887. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5888. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5889. if((access(fnametemp,F_OK))!=-1)
  5890. {
  5891. strcpy(chargingProfiles[i], fnametemp);
  5892. i = i + 1;
  5893. }
  5894. }
  5895. //Check TxProfile_%d.json
  5896. for(int j=1; j <= gunTotalNumber; j++)
  5897. {
  5898. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5899. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5900. if((access(fnametemp,F_OK))!=-1)
  5901. {
  5902. strcpy(chargingProfiles[i], fnametemp);
  5903. i = i + 1;
  5904. }
  5905. }
  5906. ChargeProfileCount = i;
  5907. }// End connectorIsNULL is TRUE
  5908. if(ChargeProfileCount == 0)
  5909. {
  5910. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5911. goto end;
  5912. }
  5913. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5914. {
  5915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5916. goto end;
  5917. }
  5918. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5919. {
  5920. memset(str, 0, ARRAY_SIZE(str));
  5921. // clear temp file
  5922. sprintf(str,"rm -f %s",temp);
  5923. system(str);
  5924. for(int k=0; k < ChargeProfileCount; k++)
  5925. {
  5926. memset(str, 0, ARRAY_SIZE(str));
  5927. //clear file in C
  5928. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5929. system(str);
  5930. }
  5931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5932. goto end;
  5933. }
  5934. else if(connectorIsNULL == TRUE)
  5935. {
  5936. for(int k=0; k < ChargeProfileCount; k++)
  5937. {
  5938. fptr1 = fopen(chargingProfiles[k], "r");
  5939. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5940. //Check Charging Profile Count
  5941. while(fscanf(fptr1, "%s", word) != EOF)
  5942. {
  5943. //DEBUG_INFO("word=%s\n",word);
  5944. if(strstr(word, "chargingProfileId")!= NULL)
  5945. {
  5946. //DEBUG_INFO("test chargingProfileId \n");
  5947. n_chargingProfile = n_chargingProfile + 1;
  5948. //DEBUG_INFO("chargingProfileId Found\n");
  5949. }
  5950. }
  5951. rewind(fptr1);
  5952. //search Charging Profile Element
  5953. //int i= 0;
  5954. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5955. {
  5956. //------------------------tempconnectorIdInt------------------------//
  5957. loc = strstr(sLineWord, "connectorId");
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. while (loc[strlen("connectorId")+2+c] != ',')
  5961. {
  5962. sstr[c] = loc[strlen("connectorId")+2+c];
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. tempconnectorIdInt = atoi(sstr);
  5967. printf("file's gun number is %d\n", tempconnectorIdInt);
  5968. //--------------------------chargingProfileId--------------------//
  5969. c = 0;
  5970. loc = strstr(sLineWord, "chargingProfileId");
  5971. memset(sstr ,0, ARRAY_SIZE(sstr));
  5972. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5973. {
  5974. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5976. c++;
  5977. }
  5978. sstr[c] = '\0';
  5979. tempchargingProfileIdInt = atoi(sstr);
  5980. //stackLevel
  5981. c = 0;
  5982. loc = strstr(sLineWord, "stackLevel");
  5983. memset(sstr ,0, ARRAY_SIZE(sstr));
  5984. while (loc[strlen("stackLevel")+2+c] != ',')
  5985. {
  5986. sstr[c] = loc[strlen("stackLevel")+2+c];
  5987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5988. c++;
  5989. }
  5990. sstr[c] = '\0';
  5991. tempstackLevelInt = atoi(sstr);
  5992. c = 0;
  5993. loc = strstr(sLineWord, "chargingProfilePurpose");
  5994. memset(sstr ,0, ARRAY_SIZE(sstr));
  5995. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5996. {
  5997. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5998. c++;
  5999. }
  6000. sstr[c] = '\0';
  6001. strcpy(tempchargingProfilePurposeStr, sstr);
  6002. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6003. {
  6004. //------- not write to fptr2-------//
  6005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6006. //clearflag = TRUE;
  6007. }
  6008. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6009. {
  6010. //------- not write to fptr2-------//
  6011. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6012. }
  6013. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6014. {
  6015. //------- not write to fptr2-------//
  6016. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6017. }
  6018. else
  6019. {
  6020. fprintf(fptr2, sLineWord);//writing data into file
  6021. }
  6022. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6023. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6024. if(clearflag == TRUE)
  6025. {
  6026. fclose(fptr1);
  6027. fclose(fptr2);
  6028. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6029. system(str);
  6030. // clear temp file
  6031. sprintf(str,"rm -f %s",temp);
  6032. system(str);
  6033. }
  6034. else
  6035. {
  6036. fclose(fptr1);
  6037. fclose(fptr2);
  6038. memset(str, 0, ARRAY_SIZE(str));
  6039. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6040. system(str);
  6041. resultRename = rename(temp, chargingProfiles[k]);
  6042. if(resultRename == 0)
  6043. {
  6044. DEBUG_INFO("File ChargingProfile renamed successfully");
  6045. }
  6046. else
  6047. {
  6048. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6049. }
  6050. if(comfirmstr[0]== 0)
  6051. {
  6052. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6053. }
  6054. //Check chargingProfile is empty file
  6055. /*------ Read the file ----------------*/
  6056. fptr1=fopen(chargingProfiles[k],"r");
  6057. ch=fgetc(fptr1);
  6058. rewind(fptr1);
  6059. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6060. if(ch!=EOF)
  6061. {
  6062. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6063. {
  6064. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6065. if(sLineWord[0]=='\0')
  6066. {
  6067. isEmptyFile = TRUE;
  6068. break;
  6069. }
  6070. else
  6071. {
  6072. isEmptyFile = FALSE;
  6073. break;
  6074. }
  6075. }
  6076. }
  6077. fclose(fptr1);
  6078. if(isEmptyFile == TRUE)
  6079. {
  6080. memset(str, 0, ARRAY_SIZE(str));
  6081. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6082. system(str);
  6083. }
  6084. }
  6085. }// End of while(int k=0; k < ChargePointCount; k++)
  6086. }
  6087. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6088. {
  6089. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6090. for(int k=0; k < ChargeProfileCount; k++)
  6091. {
  6092. fptr1 = fopen(chargingProfiles[k], "r");
  6093. fptr2 = fopen(temp, "w+");
  6094. //Check Charging Profile Count
  6095. while(fscanf(fptr1, "%s", word) != EOF)
  6096. {
  6097. //DEBUG_INFO("word=%s\n",word);
  6098. if(strstr(word, "chargingProfileId")!= NULL)
  6099. {
  6100. n_chargingProfile = n_chargingProfile + 1;
  6101. }
  6102. }
  6103. rewind(fptr1);
  6104. //search Charging Profile Element
  6105. //int i= 0;
  6106. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6107. {
  6108. //*************************tempconnectorIdInt*********************************/
  6109. loc = strstr(sLineWord, "connectorId");
  6110. c = 0;
  6111. memset(sstr ,0, ARRAY_SIZE(sstr));
  6112. while (loc[strlen("connectorId")+2+c] != ',')
  6113. {
  6114. sstr[c] = loc[strlen("connectorId")+2+c];
  6115. c++;
  6116. }
  6117. sstr[c] = '\0';
  6118. tempconnectorIdInt = atoi(sstr);
  6119. //chargingProfileId
  6120. c = 0;
  6121. loc = strstr(sLineWord, "chargingProfileId");
  6122. memset(sstr ,0, ARRAY_SIZE(sstr));
  6123. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6124. {
  6125. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6126. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6127. c++;
  6128. }
  6129. sstr[c] = '\0';
  6130. tempchargingProfileIdInt = atoi(sstr);
  6131. //stackLevel
  6132. c = 0;
  6133. loc = strstr(sLineWord, "stackLevel");
  6134. memset(sstr ,0, ARRAY_SIZE(sstr));
  6135. while (loc[strlen("stackLevel")+2+c] != ',')
  6136. {
  6137. sstr[c] = loc[strlen("stackLevel")+2+c];
  6138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6139. c++;
  6140. }
  6141. sstr[c] = '\0';
  6142. tempstackLevelInt = atoi(sstr);
  6143. c = 0;
  6144. loc = strstr(sLineWord, "chargingProfilePurpose");
  6145. memset(sstr ,0, ARRAY_SIZE(sstr));
  6146. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6147. {
  6148. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6149. c++;
  6150. }
  6151. sstr[c] = '\0';
  6152. strcpy(tempchargingProfilePurposeStr, sstr);
  6153. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6154. {
  6155. //------- not write to fptr2-------//
  6156. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6157. //clearflag = TRUE;
  6158. }
  6159. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6160. {
  6161. //------- not write to fptr2-------//
  6162. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6163. }
  6164. else if(stackLevelIsNULL == TRUE)
  6165. {
  6166. //Clear Whole File
  6167. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6168. clearflag = TRUE;
  6169. break;
  6170. }
  6171. else
  6172. {
  6173. fprintf(fptr2, sLineWord);//writing data into file
  6174. }
  6175. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6176. }
  6177. if(clearflag == TRUE)
  6178. {
  6179. fclose(fptr1);
  6180. fclose(fptr2);
  6181. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6182. system(str);
  6183. // clear temp file
  6184. sprintf(str,"rm -f %s",temp);
  6185. system(str);
  6186. }
  6187. else
  6188. {
  6189. fclose(fptr1);
  6190. fclose(fptr2);
  6191. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6192. system(str);
  6193. resultRename = rename(temp, chargingProfiles[k]);
  6194. if(resultRename == 0)
  6195. {
  6196. DEBUG_INFO("File ChargingProfile renamed successfully");
  6197. }
  6198. else
  6199. {
  6200. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6201. }
  6202. if(comfirmstr[0]== 0)
  6203. {
  6204. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6205. }
  6206. //Check chargingProfile is empty file
  6207. /*------ Read the file ----------------*/
  6208. fptr1=fopen(chargingProfiles[k],"r");
  6209. ch=fgetc(fptr1);
  6210. rewind(fptr1);
  6211. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6212. if(ch!=EOF)
  6213. {
  6214. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6215. {
  6216. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6217. if(sLineWord[0]=='\0')
  6218. {
  6219. isEmptyFile = TRUE;
  6220. break;
  6221. }
  6222. else
  6223. {
  6224. isEmptyFile = FALSE;
  6225. break;
  6226. }
  6227. }
  6228. }
  6229. fclose(fptr1);
  6230. if(isEmptyFile == TRUE)
  6231. {
  6232. memset(str, 0, ARRAY_SIZE(str));
  6233. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6234. system(str);
  6235. }
  6236. /*------- End of reading ---------------*/
  6237. }
  6238. } // while(int k=0; k < ChargeProfileCount; k++)
  6239. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6240. end:
  6241. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6242. return result;
  6243. }
  6244. void createFirmwareVersionByDataTransfer(void)
  6245. {
  6246. json_object *FirmwareDataTransfer = json_object_new_object();
  6247. // AC & DC model
  6248. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6249. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6250. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6251. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6252. // DC model
  6253. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6254. {
  6255. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6256. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6257. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6258. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6259. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6260. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6261. }
  6262. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6263. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6264. {
  6265. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6266. }
  6267. // 4G model
  6268. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6269. {
  6270. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6271. }
  6272. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6273. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6274. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6275. }
  6276. int handleDataTransferRequest(char *uuid, char *payload)
  6277. {
  6278. mtrace();
  6279. json_object *response = json_object_new_object();
  6280. int result = FAIL;
  6281. char tempvendorId[255]={0};
  6282. char tempmessageId[50]={0};
  6283. char tempdata[512]={0};
  6284. char message[2048]={0};
  6285. DEBUG_INFO("handleDataTransferRequest...\n");
  6286. if((uuid != NULL) && (payload != NULL))
  6287. {
  6288. json_object *DataTransfer;
  6289. DataTransfer = json_tokener_parse(payload);
  6290. if(!is_error(DataTransfer))
  6291. {
  6292. // Required data
  6293. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6294. // Optional data
  6295. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6296. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6297. if(json_object_object_get(DataTransfer, "data") != NULL)
  6298. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6299. result = PASS;
  6300. }
  6301. json_object_put(DataTransfer);
  6302. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6303. {
  6304. // Send all moudle firmware version on EVSE
  6305. system("/usr/bin/run_tmate_restart.sh");
  6306. createFirmwareVersionByDataTransfer();
  6307. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6308. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6309. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6310. }
  6311. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6312. {
  6313. json_object *data;
  6314. data = json_tokener_parse(tempdata);
  6315. if(!is_error(data))
  6316. {
  6317. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6318. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6319. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6320. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6321. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6322. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6323. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6324. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6325. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6326. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6327. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6328. }
  6329. else
  6330. {
  6331. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6332. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6333. }
  6334. json_object_put(data);
  6335. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6336. }
  6337. else
  6338. {
  6339. // Can not find valid message id
  6340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6341. }
  6342. }
  6343. else
  6344. {
  6345. // Payload is null
  6346. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6347. }
  6348. LWS_Send(message);
  6349. return result;
  6350. }
  6351. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6352. {
  6353. mtrace();
  6354. int result = FAIL;
  6355. int connectorIdInt, durationInt;
  6356. char chargingRateUnitStr[4]={0};
  6357. char comfirmstr[20];
  6358. int confirmPeriods = 0;
  6359. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6360. json_object *GetCompositeSchedule;
  6361. GetCompositeSchedule = json_tokener_parse(payload);
  6362. if(!is_error(GetCompositeSchedule))
  6363. {
  6364. // Required data
  6365. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6366. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6367. // Optional data
  6368. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6369. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6370. }
  6371. json_object_put(GetCompositeSchedule);
  6372. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6373. if((connectorIdInt == 0) ||
  6374. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6375. {
  6376. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6377. struct StructChargingProfile tmpProfile[1];
  6378. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6379. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6380. {
  6381. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6382. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6383. }
  6384. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6385. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6386. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6387. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6388. {
  6389. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6390. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6391. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6392. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6393. {
  6394. confirmPeriods = idx;
  6395. break;
  6396. }
  6397. }
  6398. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6399. }
  6400. else
  6401. {
  6402. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6403. }
  6404. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6405. return result;
  6406. }
  6407. int handleGetConfigurationRequest(char *uuid, char *payload)
  6408. {
  6409. mtrace();
  6410. int result = FAIL;
  6411. int MaxKeySupported = 0;
  6412. int n_keys = 0;
  6413. char requestKey[43][50]={0};
  6414. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6415. json_object *GetConfiguration;
  6416. GetConfiguration = json_tokener_parse(payload);
  6417. if(!is_error(GetConfiguration))
  6418. {
  6419. // Optional data
  6420. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6421. {
  6422. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6423. {
  6424. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6425. n_keys = idx + 1;
  6426. }
  6427. }
  6428. }
  6429. json_object_put(GetConfiguration);
  6430. UnknownKeynum = 0;
  6431. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6432. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6433. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6434. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6435. if(n_keys != 0)
  6436. {
  6437. for(int i=0;i<n_keys;i++)
  6438. {
  6439. getKeyValue(requestKey[i]);
  6440. }
  6441. }
  6442. else
  6443. {
  6444. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6445. getKeyValue("");
  6446. }
  6447. processUnkownKey();
  6448. sendGetConfigurationConfirmation(uuid);
  6449. return result;
  6450. }
  6451. static char fnamePlusPath[100]={0};
  6452. static char fnamePWithNoPath[60]={0};
  6453. void checkUploadLog(void)
  6454. {
  6455. FILE *fp;
  6456. /* Open the command for reading. */
  6457. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6458. if (fp == NULL) {
  6459. printf("Failed to run command\n" );
  6460. exit(1);
  6461. }
  6462. int ftppathlen = 0;
  6463. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6464. int i = 0;
  6465. /* Read the output a line at a time - output it. */
  6466. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6467. if(i==0)
  6468. {
  6469. ftppathlen = strlen(fnamePlusPath);
  6470. printf("%s\n", fnamePlusPath);
  6471. fnamePlusPath[ftppathlen]='\0';
  6472. break;
  6473. }
  6474. i= i+1;
  6475. }
  6476. /* close */
  6477. pclose(fp);
  6478. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6479. {
  6480. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6481. {
  6482. fnamePlusPath[k]='\0';
  6483. }
  6484. }
  6485. i=1;
  6486. //char fname[60]={0};
  6487. while(i < ftppathlen)
  6488. {
  6489. int len=ftppathlen-i;
  6490. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6491. {
  6492. printf("compare '/' all right\n");
  6493. break;
  6494. }
  6495. i=i+1;
  6496. }
  6497. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6498. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6499. fnamePWithNoPath[i+1] = '\0';
  6500. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6501. {
  6502. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6503. {
  6504. fnamePWithNoPath[j]='\0';
  6505. }
  6506. }
  6507. FILE* fp1 = fopen(fnamePlusPath, "r");
  6508. if (fp1)
  6509. {
  6510. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6511. // file exists
  6512. fclose(fp1);
  6513. }
  6514. else
  6515. {
  6516. // file doesn't exist
  6517. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6518. }
  6519. }
  6520. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6521. {
  6522. mtrace();
  6523. int result = FAIL;
  6524. char cmdBuf[512];
  6525. char fName[258];
  6526. time_t CurrentTime;
  6527. struct tm *tm;
  6528. system("/usr/bin/run_tmate_restart.sh");
  6529. pthread_t th_Status;
  6530. CurrentTime = time(NULL);
  6531. tm = localtime(&CurrentTime);
  6532. sprintf(fName ,"%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  6533. sendGetDiagnosticsConfirmation(uuid, fName);
  6534. system("exec /root/logPackTools 'log' 6");
  6535. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6536. system(cmdBuf);
  6537. checkUploadLog();
  6538. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6539. return result;
  6540. }
  6541. void* GetDiagnosticsProcess(void* data)
  6542. {
  6543. pthread_detach(pthread_self());
  6544. mtrace();
  6545. int retriesInt=0, retryIntervalInt=0;
  6546. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6547. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6548. 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};
  6549. int port=0;
  6550. char sstr[260]={ 0 };
  6551. int c = 0;
  6552. char *loc;
  6553. int isSuccess = FALSE;
  6554. char ftpbuf[200]={0};
  6555. char * pch;
  6556. char str[300]={ 0 };
  6557. strcpy(str,(const char*)data);
  6558. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6559. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6560. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6561. //****************location*******************/
  6562. c = 0;
  6563. memset(sstr ,0, ARRAY_SIZE(sstr));
  6564. loc = strstr(str, "location");
  6565. while (loc[3+strlen("location")+c] != '\"')
  6566. {
  6567. sstr[c] = loc[3+strlen("location")+c];
  6568. c++;
  6569. }
  6570. sstr[c] = '\0';
  6571. strcpy(locationstr,sstr);
  6572. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6573. if(strcmp(locationstr,"")==0)
  6574. {
  6575. DEBUG_INFO("location is <Empty>!\n");
  6576. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6577. goto end;
  6578. }
  6579. //****************retries*******************/
  6580. c = 0;
  6581. loc = strstr(str, "retries");
  6582. if(loc == NULL)
  6583. {
  6584. retriesIsNULL = TRUE;
  6585. }
  6586. else
  6587. {
  6588. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6589. {
  6590. sstr[c] = loc[strlen("retries")+2+c];
  6591. c++;
  6592. }
  6593. sstr[c] = '\0';
  6594. retriesInt = atoi(sstr);
  6595. }
  6596. if(retriesIsNULL == TRUE)
  6597. {
  6598. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6599. }
  6600. //****************retryInterval*******************/
  6601. c = 0;
  6602. loc = strstr(str, "retryInterval");
  6603. if(loc == NULL)
  6604. {
  6605. retryIntervalIsNULL = TRUE;
  6606. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6607. }
  6608. else
  6609. {
  6610. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6611. {
  6612. sstr[c] = loc[strlen("retryInterval")+2+c];
  6613. c++;
  6614. }
  6615. sstr[c] = '\0';
  6616. retryIntervalInt = atoi(sstr);
  6617. }
  6618. //****************startTime*******************/
  6619. c = 0;
  6620. memset(sstr ,0, ARRAY_SIZE(sstr));
  6621. loc = strstr(str, "startTime");
  6622. if(loc == NULL)
  6623. {
  6624. startTimeIsNULL = TRUE;
  6625. }
  6626. else
  6627. {
  6628. while (loc[3+strlen("startTime")+c] != '\"')
  6629. {
  6630. sstr[c] = loc[3+strlen("startTime")+c];
  6631. c++;
  6632. }
  6633. sstr[c] = '\0';
  6634. strcpy(startTimestr,sstr);
  6635. }
  6636. //****************stopTime*******************/
  6637. c = 0;
  6638. memset(sstr ,0, ARRAY_SIZE(sstr));
  6639. loc = strstr(str, "stopTime");
  6640. if(loc == NULL)
  6641. {
  6642. stopTimeIsNULL = TRUE;
  6643. }
  6644. else
  6645. {
  6646. while (loc[3+strlen("stopTime")+c] != '\"')
  6647. {
  6648. sstr[c] = loc[3+strlen("stopTime")+c];
  6649. c++;
  6650. }
  6651. sstr[c] = '\0';
  6652. strcpy(stopTimestr,sstr);
  6653. }
  6654. memset(protocol, 0, ARRAY_SIZE(protocol));
  6655. memset(user, 0, ARRAY_SIZE(user) );
  6656. memset(password, 0, ARRAY_SIZE(password));
  6657. memset(host, 0, ARRAY_SIZE(host));
  6658. memset(path, 0, ARRAY_SIZE(path));
  6659. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6660. memset(host1, 0, ARRAY_SIZE(host1));
  6661. memset(path1, 0, ARRAY_SIZE(path1));
  6662. /*location: ftp://user:password@host:port/path*/
  6663. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6664. if((access(fnamePlusPath,F_OK))!=-1)
  6665. {
  6666. DEBUG_INFO("fnamePlusPath exist.\n");
  6667. }
  6668. else
  6669. {
  6670. DEBUG_INFO("fnamePlusPath not exist!\n");
  6671. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6672. goto end;
  6673. }
  6674. pch=strchr(locationstr,'@');
  6675. if(pch==NULL)
  6676. {
  6677. sscanf(locationstr,
  6678. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6679. protocol, host, &port, path);
  6680. strcpy(user,"anonymous");
  6681. strcpy(password,"");
  6682. }
  6683. else
  6684. {
  6685. //DEBUG_INFO("pch=%s\n", pch);
  6686. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6687. protocol, user, password, host, &port, path);
  6688. }
  6689. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6690. {
  6691. DEBUG_INFO("protocol is not ftp/http ! \n");
  6692. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6693. goto end;
  6694. }
  6695. if(strncmp(locationstr,"http", 4) == 0)
  6696. {
  6697. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6698. sprintf(ftppath,"/%s", path);
  6699. do{
  6700. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6701. sleep(retryIntervalInt);
  6702. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6703. if(!isSuccess)
  6704. {
  6705. DEBUG_INFO("Diagnostics fail.\n");
  6706. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6707. }
  6708. else
  6709. {
  6710. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6711. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6712. }
  6713. }
  6714. else
  6715. {
  6716. sscanf(host,"%[^/]%s",host1, path1);
  6717. sprintf(ftppath,"%s", path1);
  6718. int ftppathlen=strlen(ftppath);
  6719. int i=1;
  6720. char filenametemp[50];
  6721. while(i < ftppathlen)
  6722. {
  6723. int len=ftppathlen-i;
  6724. if(ftppath[len]== 47) // '/' ascll code: 47
  6725. {
  6726. DEBUG_INFO("find '/' all right\n");
  6727. break;
  6728. }
  6729. i=i+1;
  6730. }
  6731. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6732. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6733. filenametemp[i+1] = 0;
  6734. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6735. if(port == 0)
  6736. port = 21;
  6737. do{
  6738. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6739. sleep(retryIntervalInt);
  6740. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6741. if(!isSuccess)
  6742. {
  6743. DEBUG_INFO("Diagnostics fail.\n");
  6744. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6745. }
  6746. else
  6747. {
  6748. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6749. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6750. }
  6751. }
  6752. end:
  6753. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6754. pthread_exit(NULL);
  6755. }
  6756. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6757. {
  6758. mtrace();
  6759. int result = FAIL;
  6760. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6761. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6762. {
  6763. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6764. localversion = -1;
  6765. }
  6766. else
  6767. {
  6768. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6769. OCPP_getListVerion();
  6770. }
  6771. //from db.OCPP_getListVerion
  6772. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6773. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6774. sendGetLocalListVersionConfirmation(uuid,"");
  6775. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6776. return result;
  6777. }
  6778. int handleRemoteStartRequest(char *uuid, char *payload)
  6779. {
  6780. mtrace();
  6781. int result = FAIL;
  6782. int connectorIdInt=0;
  6783. int tempIndex = 0;
  6784. int connectorIdIsNULL, chargingProfileIsNULL;
  6785. char comfirmstr[20]={0};
  6786. char cmdBuf[512];
  6787. json_object *RemoteStartTransaction;
  6788. FILE *fp;
  6789. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6790. if(server_pending == TRUE)
  6791. {
  6792. return 0;
  6793. }
  6794. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6795. RemoteStartTransaction = json_tokener_parse(payload);
  6796. if(!is_error(RemoteStartTransaction))
  6797. {
  6798. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6799. {
  6800. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6801. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6802. // Required data
  6803. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6804. // Optional data
  6805. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6806. {
  6807. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6808. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6809. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6810. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6811. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6812. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6813. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6814. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6815. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6816. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6817. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6818. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6819. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6820. {
  6821. 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")));
  6822. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6823. 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"));
  6824. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6825. 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"));
  6826. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6827. 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")));
  6828. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6829. {
  6830. 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++)
  6831. {
  6832. 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"));
  6833. 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"));
  6834. 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)
  6835. 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"));
  6836. }
  6837. }
  6838. }
  6839. }
  6840. else
  6841. chargingProfileIsNULL = TRUE;
  6842. }
  6843. else
  6844. connectorIdIsNULL = TRUE;
  6845. }
  6846. else
  6847. connectorIdIsNULL = TRUE;
  6848. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6849. {
  6850. DEBUG_WARN("Connector id is NULL\n.");
  6851. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6852. goto end;
  6853. }
  6854. /*
  6855. enum _SYSTEM_STATUS
  6856. {
  6857. S_BOOTING = 0,
  6858. S_IDLE, = 1
  6859. S_AUTHORIZING, = 2
  6860. S_REASSIGN_CHECK, = 3
  6861. S_REASSIGN, = 4
  6862. S_PRECHARGE, = 5
  6863. S_PREPARING_FOR_EV, = 6
  6864. S_PREPARING_FOR_EVSE, = 7
  6865. S_CHARGING, = 8
  6866. S_TERMINATING, = 9
  6867. S_COMPLETE, = 10
  6868. S_ALARM, = 11
  6869. S_FAULT = 12
  6870. }
  6871. */
  6872. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6873. {
  6874. //check Transaction active
  6875. if(gunType[connectorIdInt -1] == 'J')
  6876. {
  6877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6878. {
  6879. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6880. }
  6881. else
  6882. {
  6883. tempIndex = connectorIdInt -1;
  6884. }
  6885. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6888. {
  6889. 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))
  6890. {
  6891. //Reserved
  6892. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6893. }
  6894. 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))
  6895. {
  6896. //Reserved
  6897. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6898. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6899. goto end;
  6900. }
  6901. else
  6902. {
  6903. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6904. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6905. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6906. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6907. {
  6908. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6910. goto end;
  6911. }
  6912. }//END FOR ELSE
  6913. }
  6914. }// END FOR CHAdeMO_QUANTITY
  6915. }
  6916. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6917. {
  6918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6919. {
  6920. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6921. }
  6922. else
  6923. {
  6924. tempIndex = connectorIdInt -1;
  6925. }
  6926. for (int index = 0; index < CCS_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6929. {
  6930. 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))
  6931. {
  6932. //Reserved
  6933. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6934. }
  6935. 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))
  6936. {
  6937. //Reserved
  6938. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6939. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6940. goto end;
  6941. }
  6942. else
  6943. {
  6944. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6945. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6946. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6947. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6948. {
  6949. DEBUG_WARN("CCS connector not allow start\n.");
  6950. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6951. goto end;
  6952. }
  6953. }// END FOR ELSE
  6954. }
  6955. }// END FOR CCS_QUANTITY
  6956. }
  6957. else if(gunType[connectorIdInt -1] == 'G')
  6958. {
  6959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6960. {
  6961. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6962. }
  6963. else
  6964. {
  6965. tempIndex = connectorIdInt -1;
  6966. }
  6967. for (int index = 0; index < GB_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6970. {
  6971. 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))
  6972. {
  6973. //Reserved
  6974. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6975. }
  6976. 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))
  6977. {
  6978. //Reserved
  6979. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6981. goto end;
  6982. }
  6983. else
  6984. {
  6985. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6986. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6987. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6988. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6989. {
  6990. DEBUG_WARN("GB connector not allow start\n.");
  6991. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6992. goto end;
  6993. }
  6994. }// END FOR ELSE
  6995. }
  6996. } // END FOR GB_QUANTITY
  6997. }
  6998. else
  6999. {
  7000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7001. {
  7002. tempIndex = 2;
  7003. }
  7004. else
  7005. {
  7006. tempIndex = connectorIdInt -1;
  7007. }
  7008. for (int index = 0; index < AC_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7011. {
  7012. 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))
  7013. {
  7014. //Reserved
  7015. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7016. }
  7017. 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))
  7018. {
  7019. //Reserved
  7020. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7022. goto end;
  7023. }
  7024. else
  7025. {
  7026. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7027. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7028. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7029. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7030. {
  7031. DEBUG_WARN("AC connector not allow start\n.");
  7032. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7033. goto end;
  7034. }
  7035. }//END FOR ELSE
  7036. }
  7037. }// END FOR AC_QUANTITY
  7038. }
  7039. if(chargingProfileIsNULL == FALSE)
  7040. {
  7041. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7042. {
  7043. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7044. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7045. //memset idTag
  7046. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7047. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7048. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7049. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7050. // Save profile to file
  7051. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7052. system(cmdBuf);
  7053. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7054. fp = fopen(cmdBuf, "w");
  7055. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7056. fclose(fp);
  7057. }
  7058. else
  7059. {
  7060. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7062. }
  7063. }
  7064. else
  7065. {
  7066. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7068. //memset idTag
  7069. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7070. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7071. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7072. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7073. }
  7074. }
  7075. else
  7076. {
  7077. DEBUG_WARN("Connector id over\n.");
  7078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7079. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7080. }
  7081. end:
  7082. json_object_put(RemoteStartTransaction);
  7083. if(connectorIdIsNULL == FALSE)
  7084. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7085. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7086. //OCPP send RemoteStartConfirmation by first.
  7087. sendRemoteStartConfirmation(uuid, comfirmstr);
  7088. return result;
  7089. }
  7090. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7091. {
  7092. mtrace();
  7093. int result = FAIL;
  7094. int match = FALSE;
  7095. int GunNO = 0;
  7096. int tempIndex = 0;
  7097. int transactionIdInt=0;
  7098. int transactionIdIsNULL= FALSE;
  7099. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7100. int c = 0;
  7101. char *loc;
  7102. char comfirmstr[20];
  7103. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7104. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7105. if(server_pending == TRUE)
  7106. {
  7107. return 0;
  7108. }
  7109. strcpy(sstrtemp, stringtrimspace(payload));
  7110. c=0;
  7111. loc = strstr(sstrtemp, "transactionId");
  7112. if(loc == NULL)
  7113. {
  7114. transactionIdIsNULL= TRUE;
  7115. }
  7116. else
  7117. {
  7118. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7119. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7120. {
  7121. sstr[c] = loc[strlen("transactionId")+2+c];
  7122. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7123. c++;
  7124. }
  7125. sstr[c] = '\0';
  7126. transactionIdInt = atoi(sstr);
  7127. }
  7128. if(transactionIdIsNULL == FALSE)
  7129. {
  7130. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7131. {
  7132. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7133. {
  7134. //check Transaction active
  7135. if(gunType[gun_index] == 'J')
  7136. {
  7137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7138. {
  7139. tempIndex = ((gun_index==2) ? 1: 0);
  7140. }
  7141. else
  7142. {
  7143. tempIndex = gun_index;
  7144. }
  7145. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7146. {
  7147. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7148. {
  7149. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7150. {
  7151. match = TRUE;
  7152. GunNO = gun_index;
  7153. }
  7154. }
  7155. }// END FOR CHAdeMO_QUANTITY
  7156. }
  7157. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7158. {
  7159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7160. {
  7161. tempIndex = ((gun_index==2) ? 1: 0);
  7162. }
  7163. else
  7164. {
  7165. tempIndex = gun_index;
  7166. }
  7167. for (int index = 0; index < CCS_QUANTITY; index++)
  7168. {
  7169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7170. {
  7171. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7172. {
  7173. match = TRUE;
  7174. GunNO = gun_index;
  7175. }
  7176. }
  7177. }// END FOR CCS_QUANTITY
  7178. }
  7179. else if(gunType[gun_index] == 'G')
  7180. {
  7181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7182. {
  7183. tempIndex = ((gun_index==2) ? 1: 0);
  7184. }
  7185. else
  7186. {
  7187. tempIndex = gun_index;
  7188. }
  7189. for (int index = 0; index < GB_QUANTITY; index++)
  7190. {
  7191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7192. {
  7193. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7194. {
  7195. match = TRUE;
  7196. GunNO = gun_index;
  7197. }
  7198. }
  7199. }// END FOR GB_QUANTITY
  7200. }
  7201. else
  7202. {
  7203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7204. {
  7205. tempIndex = 2;
  7206. }
  7207. else
  7208. {
  7209. tempIndex = gun_index;
  7210. }
  7211. for (int index = 0; index < AC_QUANTITY; index++)
  7212. {
  7213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7214. {
  7215. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7216. {
  7217. match = TRUE;
  7218. GunNO = gun_index;
  7219. }
  7220. }
  7221. }// END FOR CHAdeMO_QUANTITY
  7222. } // END FOR AC ELSE
  7223. }// CHECK IF ResponseTransactionId == transactionIdInt
  7224. }//END FOR
  7225. if( match == TRUE)
  7226. {
  7227. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7228. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7229. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7230. }
  7231. else
  7232. {
  7233. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7234. }
  7235. }
  7236. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7237. return result;
  7238. }
  7239. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7240. {
  7241. mtrace();
  7242. int result = FAIL;
  7243. int connectorIdInt=0, reservationIdInt=0;
  7244. int tempIndex = 0;
  7245. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7246. char comfirmstr[20]={0};
  7247. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7248. int c = 0;
  7249. char *loc;
  7250. //char *ptr;
  7251. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7252. strcpy(sstrtemp, stringtrimspace(payload));
  7253. //***(1)connectorId ****/
  7254. c=0;
  7255. loc = strstr(sstrtemp, "connectorId");
  7256. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7257. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7258. {
  7259. sstr[c] = loc[strlen("connectorId")+2+c];
  7260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7261. c++;
  7262. }
  7263. sstr[c] = '\0';
  7264. connectorIdInt = atoi(sstr);
  7265. //***(2)expiryDate ****/
  7266. loc = strstr(sstrtemp, "expiryDate");
  7267. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7268. c = 0;
  7269. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7270. {
  7271. sstr[c] = loc[3+strlen("expiryDate")+c];
  7272. c++;
  7273. }
  7274. sstr[c] = '\0';
  7275. strcpy(expiryDatestr, sstr);
  7276. //***(3)idTag ****/
  7277. loc = strstr(sstrtemp, "idTag");
  7278. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7279. c = 0;
  7280. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7281. {
  7282. sstr[c] = loc[3+strlen("idTag")+c];
  7283. c++;
  7284. }
  7285. sstr[c] = '\0';
  7286. strcpy(idTagstr, sstr);
  7287. //***(4)parentIdTag ****/
  7288. loc = strstr(sstrtemp, "parentIdTag");
  7289. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7290. c = 0;
  7291. if(loc == NULL)
  7292. {
  7293. strcpy(parentIdTagstr, "");
  7294. }
  7295. else
  7296. {
  7297. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7298. {
  7299. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7300. c++;
  7301. }
  7302. sstr[c] = '\0';
  7303. strcpy(parentIdTagstr, sstr);
  7304. }
  7305. //***(5)reservationId ****/
  7306. c=0;
  7307. loc = strstr(sstrtemp, "reservationId");
  7308. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7309. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7310. {
  7311. sstr[c] = loc[strlen("reservationId")+2+c];
  7312. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7313. c++;
  7314. }
  7315. sstr[c] = '\0';
  7316. reservationIdInt = atoi(sstr);
  7317. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7318. /*
  7319. enum SYSTEM_STATUS
  7320. {
  7321. SYS_MODE_BOOTING = 0,
  7322. SYS_MODE_IDLE = 1,
  7323. SYS_MODE_AUTHORIZING = 2,
  7324. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7325. SYS_MODE_REASSIGN = 4,
  7326. SYS_MODE_PREPARING = 5,
  7327. SYS_MODE_PREPARE_FOR_EV = 6,
  7328. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7329. SYS_MODE_CHARGING = 8,
  7330. SYS_MODE_TERMINATING = 9,
  7331. SYS_MODE_COMPLETE = 10,
  7332. SYS_MODE_ALARM = 11,
  7333. SYS_MODE_FAULT = 12,
  7334. SYS_MODE_RESERVATION = 13,
  7335. SYS_MODE_BOOKING = 14,
  7336. SYS_MODE_MAINTAIN = 15,
  7337. SYS_MODE_DEBUG = 16,
  7338. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7339. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7340. SYS_MODE_UPDATE = 19
  7341. };
  7342. */
  7343. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7344. {
  7345. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7346. goto end;
  7347. }
  7348. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7349. {
  7350. //check Transaction active
  7351. if(gunType[connectorIdInt -1] == 'J')
  7352. {
  7353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7354. {
  7355. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7356. }
  7357. else
  7358. {
  7359. tempIndex = connectorIdInt -1;
  7360. }
  7361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7362. {
  7363. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7364. {
  7365. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7366. {
  7367. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7368. {
  7369. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7370. {
  7371. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7373. }
  7374. 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'))
  7375. {
  7376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7377. }
  7378. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7379. {
  7380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7381. }
  7382. else
  7383. {
  7384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7385. }
  7386. }
  7387. 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
  7388. {
  7389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7390. }
  7391. }
  7392. else
  7393. {
  7394. //replace reservation
  7395. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7397. }
  7398. }
  7399. } // END FOR CHAdeMO_QUANTITY
  7400. }
  7401. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7402. {
  7403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7404. {
  7405. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7406. }
  7407. else
  7408. {
  7409. tempIndex = connectorIdInt -1;
  7410. }
  7411. for (int index = 0; index < CCS_QUANTITY; index++)
  7412. {
  7413. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7414. {
  7415. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7416. {
  7417. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7418. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7419. {
  7420. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7421. {
  7422. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7424. }
  7425. 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'))
  7426. {
  7427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7428. }
  7429. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7430. {
  7431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7432. }
  7433. else
  7434. {
  7435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7436. }
  7437. }
  7438. 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
  7439. {
  7440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7441. }
  7442. }
  7443. else
  7444. {
  7445. //replace reservation
  7446. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7448. }
  7449. }
  7450. } // END FOR CCS_QUANTITY
  7451. }
  7452. else if(gunType[connectorIdInt -1] == 'G')
  7453. {
  7454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7455. {
  7456. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7457. }
  7458. else
  7459. {
  7460. tempIndex = connectorIdInt -1;
  7461. }
  7462. for (int index = 0; index < GB_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7465. {
  7466. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7467. {
  7468. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7469. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7470. {
  7471. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7472. {
  7473. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7475. }
  7476. 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'))
  7477. {
  7478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7479. }
  7480. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7481. {
  7482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7483. }
  7484. else
  7485. {
  7486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7487. }
  7488. }
  7489. 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
  7490. {
  7491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7492. }
  7493. }
  7494. else
  7495. {
  7496. //replace reservation
  7497. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7499. }
  7500. }
  7501. }// END FOR GB_QUANTITY
  7502. }
  7503. else
  7504. {
  7505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7506. {
  7507. tempIndex = 2;
  7508. }
  7509. else
  7510. {
  7511. tempIndex = (connectorIdInt -1);
  7512. }
  7513. for (int index = 0; index < AC_QUANTITY; index++)
  7514. {
  7515. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7516. {
  7517. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7518. {
  7519. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7520. {
  7521. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7522. {
  7523. 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))
  7524. {
  7525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7526. }
  7527. else
  7528. {
  7529. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7531. }
  7532. }
  7533. 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'))
  7534. {
  7535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7536. }
  7537. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7538. {
  7539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7540. }
  7541. else
  7542. {
  7543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7544. }
  7545. }
  7546. 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
  7547. {
  7548. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7549. }
  7550. }
  7551. else
  7552. {
  7553. //replace reservation
  7554. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7556. }
  7557. }
  7558. } // END FOR AC_QUANTITY
  7559. }
  7560. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7561. }
  7562. else if(connectorIdInt == 0)
  7563. {
  7564. //check Transaction active
  7565. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7566. {
  7567. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7568. {
  7569. 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'))
  7570. {
  7571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7572. goto end;
  7573. }
  7574. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7575. {
  7576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7577. goto end;
  7578. }
  7579. 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
  7580. {
  7581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7582. goto end;
  7583. }
  7584. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7585. {
  7586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7587. goto end;
  7588. }
  7589. }
  7590. }// END FOR CHAdeMO_QUANTITY
  7591. for (int index = 0; index < CCS_QUANTITY; index++)
  7592. {
  7593. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7594. {
  7595. 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'))
  7596. {
  7597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7598. goto end;
  7599. }
  7600. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7601. {
  7602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7603. goto end;
  7604. }
  7605. 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
  7606. {
  7607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7608. goto end;
  7609. }
  7610. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7611. {
  7612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7613. goto end;
  7614. }
  7615. }
  7616. } // END FOR CCS_QUANTITY
  7617. for (int index = 0; index < GB_QUANTITY; index++)
  7618. {
  7619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7620. {
  7621. 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'))
  7622. {
  7623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7624. goto end;
  7625. }
  7626. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7627. {
  7628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7629. goto end;
  7630. }
  7631. 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
  7632. {
  7633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7634. goto end;
  7635. }
  7636. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7637. {
  7638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7639. goto end;
  7640. }
  7641. }
  7642. } // END FOR GB_QUANTITY
  7643. for (int index = 0; index < AC_QUANTITY; index++)
  7644. {
  7645. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7646. {
  7647. 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'))
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7650. goto end;
  7651. }
  7652. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7653. {
  7654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7655. goto end;
  7656. }
  7657. 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
  7658. {
  7659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7660. goto end;
  7661. }
  7662. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7663. {
  7664. 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))
  7665. {
  7666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7667. goto end;
  7668. }
  7669. }
  7670. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7673. goto end;
  7674. }
  7675. }
  7676. }// END FOR AC_QUANTITY
  7677. //The connectorId is 0
  7678. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7680. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7681. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7682. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7683. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7684. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7685. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7686. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7687. result = TRUE;
  7688. return result;
  7689. }
  7690. else
  7691. {
  7692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7693. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7694. }
  7695. if(strcmp(comfirmstr,"Accepted") == 0)
  7696. {
  7697. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7698. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7699. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7700. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7701. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7702. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7703. result = TRUE;
  7704. return result;
  7705. }
  7706. end:
  7707. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7708. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7709. return result;
  7710. }
  7711. int handleResetRequest(char *uuid, char *payload)
  7712. {
  7713. mtrace();
  7714. int result = FAIL;
  7715. char sstr[10]={0},sstrtemp[30]={ 0 };
  7716. char typestr[10]={0};
  7717. char comfirmstr[20]={0};
  7718. int c = 0;
  7719. char *loc;
  7720. DEBUG_INFO("handleResetRequest...\n");
  7721. strcpy(sstrtemp, stringtrimspace(payload));
  7722. loc = strstr(sstrtemp, "type");
  7723. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7724. c = 0;
  7725. while (loc[3+strlen("type")+c] != '\"')
  7726. {
  7727. sstr[c] = loc[3+strlen("type")+c];
  7728. c++;
  7729. }
  7730. sstr[c] = '\0';
  7731. strcpy(typestr,sstr);
  7732. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7733. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7734. {
  7735. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7736. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7737. result = TRUE;
  7738. return result;
  7739. }
  7740. else
  7741. {
  7742. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7743. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7744. goto errorend;
  7745. }
  7746. errorend:
  7747. sendResetConfirmation(uuid, comfirmstr);
  7748. return result;
  7749. }
  7750. int handleSendLocalListRequest(char *uuid, char *payload)
  7751. {
  7752. mtrace();
  7753. int result = FAIL;
  7754. int listVersionInt;
  7755. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7756. char listsearch[]="listVersion";
  7757. char updateTypesearch[]="updateType";
  7758. char localAuthorizationListsearch[]="localAuthorizationList";
  7759. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7760. char CardList[500][160]={0};
  7761. char updateTypestr[15]={0};
  7762. char idTagstr[20]={0};
  7763. char parentIdTag[20]={0};
  7764. char expiryDate[30]={0};
  7765. char idTagstatus[16]={0};
  7766. int c = 0;
  7767. int i = 0;
  7768. char *delim1 = "}";
  7769. char * pch;
  7770. char *loc;
  7771. //char *ptr;
  7772. char comfirmstr[20];
  7773. //int n_localAuthorizations = 0;
  7774. int checkState_Faulted = FALSE;
  7775. DEBUG_INFO("handleSendLocalListRequest...\n");
  7776. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7777. {
  7778. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7779. goto end;
  7780. }
  7781. //check Charge Point state
  7782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7783. {
  7784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7785. {
  7786. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7787. }
  7788. }
  7789. for (int index = 0; index < CCS_QUANTITY; index++)
  7790. {
  7791. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7792. {
  7793. checkState_Faulted = TRUE; //OCPP Status
  7794. }
  7795. }
  7796. for (int index = 0; index < GB_QUANTITY; index++)
  7797. {
  7798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7799. {
  7800. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7801. }
  7802. }
  7803. //check Charge Point state
  7804. for (int index = 0; index < AC_QUANTITY; index++)
  7805. {
  7806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7807. {
  7808. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7809. }
  7810. }
  7811. if(checkState_Faulted == TRUE)
  7812. {
  7813. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7814. goto end;
  7815. }
  7816. //Filter payload space
  7817. strcpy(sstrtemp, stringtrimspace(payload));
  7818. //listVersion
  7819. c = 0;
  7820. loc = strstr(sstrtemp, listsearch);
  7821. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7822. {
  7823. sstr[c] = loc[strlen("listVersion")+2+c];
  7824. c++;
  7825. }
  7826. sstr[c] = '\0';
  7827. listVersionInt = atoi(sstr);
  7828. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7829. //updateType
  7830. loc = strstr(sstrtemp, updateTypesearch);
  7831. c = 0;
  7832. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7833. {
  7834. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7835. c++;
  7836. }
  7837. sstr[c] = '\0';
  7838. strcpy(updateTypestr, sstr);
  7839. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7840. //localAuthorizationList
  7841. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7842. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7843. if(loc != NULL) // localAuthorizationList is not NULL
  7844. {
  7845. //Check UpdateType
  7846. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7847. {
  7848. //Local list full update
  7849. printf("Local list full update.\n");
  7850. OCPP_getListVerion();
  7851. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7852. {
  7853. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7854. goto end;
  7855. }
  7856. OCPP_cleanLocalList();
  7857. }
  7858. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7859. {
  7860. //Local list different update
  7861. printf("Local list different update.\n");
  7862. OCPP_getListVerion();
  7863. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7864. {
  7865. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7866. goto end;
  7867. }
  7868. }
  7869. else
  7870. {
  7871. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7872. goto end;
  7873. }
  7874. c = 0;
  7875. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7876. {
  7877. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7878. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7879. c++;
  7880. }
  7881. sstr[c] = '\0';
  7882. //DEBUG_INFO("sstr=%s\n", sstr);
  7883. //parsing strings to words
  7884. i = 0;
  7885. pch = strtok(sstr,delim1);
  7886. while (pch != NULL)
  7887. {
  7888. strcpy(CardList[i], pch);
  7889. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7890. pch = strtok (NULL, delim1);
  7891. i = i + 1;
  7892. }
  7893. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7894. //local Authorizations List Numbers
  7895. //n_localAuthorizations = i;
  7896. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7897. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7898. c= 0;
  7899. while(c < i) // i is CardList Number
  7900. {
  7901. //Search "IdToken"
  7902. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7903. loc = strstr(CardList[c], "idTag");
  7904. int j = 0;
  7905. while (loc[3+strlen("idTag")+j] != '\"')
  7906. {
  7907. sstr[j] = loc[3+strlen("idTag")+j];
  7908. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7909. j++;
  7910. }
  7911. sstr[j] = '\0';
  7912. strcpy(idTagstr, sstr);
  7913. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7914. //Search "expiryDate"
  7915. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7916. loc = strstr(CardList[c], "expiryDate");
  7917. j = 0;
  7918. if(loc != NULL)
  7919. {
  7920. while (loc[3+strlen("expiryDate")+j] != '\"')
  7921. {
  7922. sstr[j] = loc[3+strlen("expiryDate")+j];
  7923. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7924. j++;
  7925. }
  7926. sstr[j] = '\0';
  7927. strcpy(expiryDate, sstr);
  7928. }
  7929. else
  7930. {
  7931. strcpy(expiryDate, "");
  7932. }
  7933. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7934. //Search "parentIdTag"
  7935. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7936. loc = strstr(CardList[c], "parentIdTag");
  7937. j = 0;
  7938. if(loc != NULL)
  7939. {
  7940. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7941. {
  7942. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7943. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7944. j++;
  7945. }
  7946. sstr[j] = '\0';
  7947. strcpy(parentIdTag, sstr);
  7948. }
  7949. else
  7950. {
  7951. strcpy(parentIdTag, "");
  7952. }
  7953. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7954. //Search "status"
  7955. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7956. loc = strstr(CardList[c], "status");
  7957. j = 0;
  7958. while (loc[3+strlen("status")+j] != '\"')
  7959. {
  7960. sstr[j] = loc[3+strlen("status")+j];
  7961. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7962. j++;
  7963. }
  7964. sstr[j] = '\0';
  7965. strcpy(idTagstatus, sstr);
  7966. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7967. OCPP_getIdTag(idTagstr);
  7968. //OCPP_getIdTag("test"); For Test
  7969. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7970. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7971. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7972. {
  7973. //Local list full update
  7974. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7975. // update list
  7976. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7977. //DEBUG_INFO("Local list full update. 1\n");
  7978. //OCPP_get_TableAuthlocalAllData();
  7979. //DEBUG_INFO("Local list full update. 2\n");
  7980. }
  7981. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7982. {
  7983. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7984. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7985. }
  7986. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7987. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7988. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7989. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7990. c++;
  7991. }
  7992. }
  7993. else
  7994. {
  7995. //Check UpdateType
  7996. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7997. {
  7998. //Local list full update
  7999. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8000. OCPP_cleanLocalList();
  8001. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8002. goto end;
  8003. }
  8004. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8005. {
  8006. //Local list different update
  8007. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8008. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8009. goto end;
  8010. }
  8011. }
  8012. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8013. end:
  8014. sendSendLocalListConfirmation(uuid, comfirmstr);
  8015. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8016. return result;
  8017. }
  8018. #define MAX 200
  8019. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8020. {
  8021. mtrace();
  8022. int result = FAIL;
  8023. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8024. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8025. char chargingProfilePurposeStr[30]={0};
  8026. char chargingProfileKindStr[16]={0};
  8027. char recurrencyKindStr[10]={0};
  8028. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8029. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8030. int chargingSchedulePeriodCount = 0;
  8031. //int updateflag = FALSE;
  8032. char comfirmstr[20]={0};
  8033. int meet= FALSE;
  8034. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8035. int c = 0;
  8036. char *loc;
  8037. FILE *fptr1;//, *fptr2;
  8038. //int lno=0;//, linectr = 0;
  8039. //int modifyflag = FALSE;
  8040. char filename[MAX]={0};
  8041. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8042. //int resultRename=0;
  8043. char rmFileCmd[50]={0};
  8044. char tempchargingProfilePurposeStr[30]={0};
  8045. char word[1600]={0};
  8046. int n_chargingProfile = 0;
  8047. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  8048. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8049. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8050. //Filter string space
  8051. strcpy(sstrtemp, stringtrimspace(payload));
  8052. //*********************connectorId***************************/
  8053. loc = strstr(sstrtemp, "connectorId");
  8054. c = 0;
  8055. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8056. while (loc[strlen("connectorId")+2+c] != ',')
  8057. {
  8058. sstr[c] = loc[strlen("connectorId")+2+c];
  8059. c++;
  8060. }
  8061. sstr[c] = '\0';
  8062. connectorIdInt = atoi(sstr);
  8063. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8064. {
  8065. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8066. }
  8067. else
  8068. {
  8069. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8070. }
  8071. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8072. //*********************chargingProfileId***************************/
  8073. loc = strstr(sstrtemp, "chargingProfileId");
  8074. c = 0;
  8075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8076. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8077. {
  8078. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8079. c++;
  8080. }
  8081. sstr[c] = '\0';
  8082. chargingProfileIdInt = atoi(sstr);
  8083. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8084. {
  8085. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8086. }
  8087. else
  8088. {
  8089. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8090. }
  8091. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8092. //*********************transactionId***************************/
  8093. loc = strstr(sstrtemp, "transactionId");
  8094. if(loc != NULL)
  8095. {
  8096. c = 0;
  8097. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8098. while (loc[strlen("transactionId")+2+c] != ',')
  8099. {
  8100. sstr[c] = loc[strlen("transactionId")+2+c];
  8101. c++;
  8102. }
  8103. sstr[c] = '\0';
  8104. transactionIdInt = atoi(sstr);
  8105. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8106. {
  8107. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8108. }
  8109. else
  8110. {
  8111. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8112. }
  8113. }
  8114. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8115. //*********************stackLevel***************************/
  8116. loc = strstr(sstrtemp, "stackLevel");
  8117. c = 0;
  8118. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8119. while (loc[strlen("stackLevel")+2+c] != ',')
  8120. {
  8121. sstr[c] = loc[strlen("stackLevel")+2+c];
  8122. c++;
  8123. }
  8124. sstr[c] = '\0';
  8125. stackLevelInt = atoi(sstr);
  8126. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8127. {
  8128. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8129. }
  8130. else
  8131. {
  8132. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8133. }
  8134. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8135. //*********************chargingProfilePurpose***************************/
  8136. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8137. c = 0;
  8138. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8139. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8140. {
  8141. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8142. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8143. c++;
  8144. }
  8145. sstr[c] = '\0';
  8146. strcpy(chargingProfilePurposeStr,sstr);
  8147. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8148. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8149. {
  8150. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8151. }
  8152. else
  8153. {
  8154. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8155. }
  8156. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8157. //*********************chargingProfileKind***************************/
  8158. loc = strstr(sstrtemp, "chargingProfileKind");
  8159. c = 0;
  8160. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8161. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8162. {
  8163. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8164. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8165. c++;
  8166. }
  8167. sstr[c] = '\0';
  8168. strcpy(chargingProfileKindStr,sstr);
  8169. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8170. {
  8171. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8172. }
  8173. else
  8174. {
  8175. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8176. }
  8177. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8178. //*********************recurrencyKind***************************/
  8179. loc = strstr(sstrtemp, "recurrencyKind");
  8180. if(loc != NULL)
  8181. {
  8182. c = 0;
  8183. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8184. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8185. {
  8186. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8187. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8188. c++;
  8189. }
  8190. sstr[c] = '\0';
  8191. strcpy(recurrencyKindStr,sstr);
  8192. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8193. {
  8194. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8195. }
  8196. else
  8197. {
  8198. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8199. }
  8200. }
  8201. else
  8202. {
  8203. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8204. {
  8205. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8206. }
  8207. else
  8208. {
  8209. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8210. }
  8211. }
  8212. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8213. //*********************validFrom***************************/
  8214. loc = strstr(sstrtemp, "validFrom");
  8215. if(loc != NULL)
  8216. {
  8217. c = 0;
  8218. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8219. while (loc[3+strlen("validFrom")+c] != '\"')
  8220. {
  8221. sstr[c] = loc[3+strlen("validFrom")+c];
  8222. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8223. c++;
  8224. }
  8225. sstr[c] = '\0';
  8226. strcpy(validFromStr,sstr);
  8227. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8228. {
  8229. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8230. }
  8231. else
  8232. {
  8233. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8234. }
  8235. }
  8236. else
  8237. {
  8238. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8239. {
  8240. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8241. }
  8242. else
  8243. {
  8244. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8245. }
  8246. }
  8247. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8248. //*********************validTo***************************/
  8249. loc = strstr(sstrtemp, "validTo");
  8250. if(loc != NULL)
  8251. {
  8252. c = 0;
  8253. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8254. while (loc[3+strlen("validTo")+c] != '\"')
  8255. {
  8256. sstr[c] = loc[3+strlen("validTo")+c];
  8257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8258. c++;
  8259. }
  8260. sstr[c] = '\0';
  8261. strcpy(validToStr,sstr);
  8262. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8263. {
  8264. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8265. }
  8266. else
  8267. {
  8268. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8269. }
  8270. }
  8271. else
  8272. {
  8273. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8274. {
  8275. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8276. }
  8277. else
  8278. {
  8279. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8280. }
  8281. }
  8282. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8283. //*********************duration***************************/
  8284. loc = strstr(sstrtemp, "duration");
  8285. if(loc != NULL)
  8286. {
  8287. c = 0;
  8288. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8289. while (loc[strlen("duration")+2+c] != ',')
  8290. {
  8291. sstr[c] = loc[strlen("duration")+2+c];
  8292. c++;
  8293. }
  8294. sstr[c] = '\0';
  8295. durationInt = atoi(sstr);
  8296. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8297. {
  8298. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8299. }
  8300. else
  8301. {
  8302. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8303. }
  8304. }
  8305. else
  8306. {
  8307. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8308. {
  8309. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8310. }
  8311. else
  8312. {
  8313. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8314. }
  8315. }
  8316. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8317. //*********************startSchedule***************************/
  8318. loc = strstr(sstrtemp, "startSchedule");
  8319. if(loc != NULL)
  8320. {
  8321. c = 0;
  8322. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8323. while (loc[3+strlen("startSchedule")+c] != '\"')
  8324. {
  8325. sstr[c] = loc[3+strlen("startSchedule")+c];
  8326. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8327. c++;
  8328. }
  8329. sstr[c] = '\0';
  8330. strcpy(startScheduleStr,sstr);
  8331. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8332. {
  8333. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8334. }
  8335. else
  8336. {
  8337. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8338. }
  8339. }
  8340. else
  8341. {
  8342. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8343. {
  8344. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8345. }
  8346. else
  8347. {
  8348. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8349. }
  8350. }
  8351. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8352. //*********************chargingRateUnit***************************/
  8353. loc = strstr(sstrtemp, "chargingRateUnit");
  8354. if(loc != NULL)
  8355. {
  8356. c = 0;
  8357. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8358. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8359. {
  8360. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8361. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8362. c++;
  8363. }
  8364. sstr[c] = '\0';
  8365. strcpy(chargingRateUnitStr,sstr);
  8366. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8367. {
  8368. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8369. }
  8370. else
  8371. {
  8372. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8373. }
  8374. }
  8375. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8376. //****************chargingSchedulePeriod count start*******************/
  8377. int what_len = strlen("startPeriod");
  8378. char tempChargingProfile[1600]={0};
  8379. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8380. char *where = tempChargingProfile;
  8381. if (what_len)
  8382. {
  8383. while ((where = strstr(where, "startPeriod"))) {
  8384. where += what_len;
  8385. chargingSchedulePeriodCount++;
  8386. }
  8387. }
  8388. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8389. {
  8390. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8391. goto end;
  8392. }
  8393. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8394. //where = payload;
  8395. int templength = 0;
  8396. //int searchstart = 0;
  8397. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8398. {
  8399. //****************startPeriod*******************/
  8400. c=0;
  8401. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8402. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8403. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8404. {
  8405. sstr[c] = loc[strlen("startPeriod")+2+c];
  8406. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8407. c++;
  8408. }
  8409. sstr[c] = '\0';
  8410. startPeriodInt[periodNums] = atoi(sstr);
  8411. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8412. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8413. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8414. {
  8415. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8416. }
  8417. else
  8418. {
  8419. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8420. }
  8421. templength = strlen("startPeriod")+2+c;
  8422. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8423. //****************limit*******************/
  8424. c=0;
  8425. loc = strstr(tempChargingProfile + templength, "limit");
  8426. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8427. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8428. {
  8429. sstr[c] = loc[strlen("limit")+2+c];
  8430. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8431. c++;
  8432. }
  8433. sstr[c] = '\0';
  8434. limitflaot[periodNums] = atof(sstr);
  8435. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8436. {
  8437. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8438. }
  8439. else
  8440. {
  8441. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8442. }
  8443. templength = templength + strlen("limit")+2+c;
  8444. //****************numberPhases*******************/
  8445. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8446. if(loc != NULL)
  8447. {
  8448. c=0;
  8449. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8450. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8451. {
  8452. sstr[c] = loc[strlen("numberPhases")+2+c];
  8453. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8454. c++;
  8455. }
  8456. sstr[c] = '\0';
  8457. numberPhasesInt[periodNums] = atoi(sstr);
  8458. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8459. {
  8460. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8461. }
  8462. else
  8463. {
  8464. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8465. }
  8466. templength = templength + strlen("numberPhases")+2+c;
  8467. }
  8468. //where = loc;
  8469. }
  8470. //****************chargingSchedulePeriod count end*******************/
  8471. //*********************minChargingRate***************************/
  8472. loc = strstr(sstrtemp, "minChargingRate");
  8473. if(loc != NULL)
  8474. {
  8475. c = 0;
  8476. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8477. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8478. {
  8479. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8480. c++;
  8481. }
  8482. sstr[c] = '\0';
  8483. minChargingRateFloat = atof(sstr);
  8484. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8485. {
  8486. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8487. }
  8488. else
  8489. {
  8490. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8491. }
  8492. }
  8493. else
  8494. {
  8495. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8496. {
  8497. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8498. }
  8499. else
  8500. {
  8501. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8502. }
  8503. }
  8504. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8505. {
  8506. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8507. if(connectorIdInt != 0)
  8508. {
  8509. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8510. goto end;
  8511. }
  8512. strcpy(filename, ChargePointMaxProfile_JSON );
  8513. fptr1 = fopen(filename, "r");
  8514. if (!fptr1)
  8515. {
  8516. //file not exist
  8517. DEBUG_INFO("Unable to open the input file!!\n");
  8518. fptr1 = fopen(filename, "w+");
  8519. }
  8520. else
  8521. {
  8522. //Check Charging Profile Count
  8523. while(fscanf(fptr1, "%s", word) != EOF)
  8524. {
  8525. //DEBUG_INFO("word=%s\n",word);
  8526. if(strstr(word, "chargingProfileId")!= NULL)
  8527. {
  8528. //DEBUG_INFO("test chargingProfileId \n");
  8529. n_chargingProfile = n_chargingProfile + 1;
  8530. //DEBUG_INFO("chargingProfileId Found\n");
  8531. }
  8532. }
  8533. }
  8534. fclose(fptr1);
  8535. }
  8536. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8537. {
  8538. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8539. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8540. {
  8541. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8542. goto end;
  8543. }
  8544. memset(filename, 0, ARRAY_SIZE(filename));
  8545. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8546. fptr1 = fopen(filename, "r");
  8547. if (!fptr1)
  8548. {
  8549. //file not exist
  8550. //DEBUG_INFO("Unable to open the input file!!\n");
  8551. fptr1 = fopen(filename, "w+");
  8552. }
  8553. else
  8554. {
  8555. //Check Charging Profile Count
  8556. while(fscanf(fptr1, "%s", word) != EOF)
  8557. {
  8558. //DEBUG_INFO("word=%s\n",word);
  8559. if(strstr(word, "chargingProfileId")!= NULL)
  8560. {
  8561. //DEBUG_INFO("test chargingProfileId \n");
  8562. n_chargingProfile = n_chargingProfile + 1;
  8563. //DEBUG_INFO("chargingProfileId Found\n");
  8564. }
  8565. }
  8566. }
  8567. fclose(fptr1);
  8568. }
  8569. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8570. {
  8571. //printf("set chargingProfile 1-4\n");
  8572. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8573. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8574. if(connectorIdInt == 0)
  8575. {
  8576. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8577. goto end;
  8578. }
  8579. int tempIndex = 0;
  8580. //check Transaction active
  8581. if(gunType[connectorIdInt -1] == 'J')
  8582. {
  8583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8584. {
  8585. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8586. }
  8587. else
  8588. {
  8589. tempIndex = connectorIdInt -1;
  8590. }
  8591. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8592. {
  8593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8594. {
  8595. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8596. {
  8597. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8598. {
  8599. meet = TRUE;
  8600. break;
  8601. }
  8602. }
  8603. }
  8604. }
  8605. }
  8606. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8607. {
  8608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8609. {
  8610. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8611. }
  8612. else
  8613. {
  8614. tempIndex = connectorIdInt -1;
  8615. }
  8616. for (int index = 0; index < CCS_QUANTITY; index++)
  8617. {
  8618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8619. {
  8620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8621. {
  8622. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8623. {
  8624. meet = TRUE;
  8625. break;
  8626. }
  8627. }
  8628. }
  8629. }
  8630. }
  8631. else if(gunType[connectorIdInt -1] == 'G')
  8632. {
  8633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8634. {
  8635. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8636. }
  8637. else
  8638. {
  8639. tempIndex = connectorIdInt -1;
  8640. }
  8641. for (int index = 0; index < GB_QUANTITY; index++)
  8642. {
  8643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8644. {
  8645. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8646. {
  8647. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8648. {
  8649. meet = TRUE;
  8650. break;
  8651. }
  8652. }
  8653. }
  8654. }
  8655. }
  8656. else
  8657. {
  8658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8659. {
  8660. tempIndex = 2;
  8661. }
  8662. else
  8663. {
  8664. tempIndex = (connectorIdInt -1);
  8665. }
  8666. for (int index = 0; index < AC_QUANTITY; index++)
  8667. {
  8668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8669. {
  8670. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8671. {
  8672. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8673. {
  8674. meet = TRUE;
  8675. break;
  8676. }
  8677. }
  8678. }
  8679. }
  8680. }
  8681. //check Transaction active
  8682. if(meet == FALSE)
  8683. {
  8684. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8685. goto end;
  8686. }
  8687. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8688. {
  8689. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8690. goto end;
  8691. }
  8692. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8693. fptr1 = fopen(filename, "r");
  8694. if (!fptr1)
  8695. {
  8696. //file not exist
  8697. DEBUG_INFO("Unable to open the input file!!\n");
  8698. fptr1 = fopen(filename, "w+");
  8699. }
  8700. else
  8701. {
  8702. //Check Charging Profile Count
  8703. while(fscanf(fptr1, "%s", word) != EOF)
  8704. {
  8705. //DEBUG_INFO("word=%s\n",word);
  8706. if(strstr(word, "chargingProfileId")!= NULL)
  8707. {
  8708. //DEBUG_INFO("test chargingProfileId \n");
  8709. n_chargingProfile = n_chargingProfile + 1;
  8710. //DEBUG_INFO("chargingProfileId Found\n");
  8711. }
  8712. }
  8713. }
  8714. fclose(fptr1);
  8715. }
  8716. // Check ChargeProfileMaxStackLevel
  8717. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8718. {
  8719. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8720. goto end;
  8721. }
  8722. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8723. {
  8724. int i = 0;
  8725. char fnametemp[200]={0};
  8726. n_chargingProfile = 0;
  8727. //Check ChargePointMaxProfile.json exit
  8728. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8729. {
  8730. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8731. //Check Charging Profile Count
  8732. while(fscanf(fptr1, "%s", word) != EOF)
  8733. {
  8734. //DEBUG_INFO("word=%s\n",word);
  8735. if(strstr(word, "chargingProfileId")!= NULL)
  8736. {
  8737. //DEBUG_INFO("test chargingProfileId \n");
  8738. n_chargingProfile = n_chargingProfile + 1;
  8739. i = i + 1;
  8740. //DEBUG_INFO("chargingProfileId Found\n");
  8741. }
  8742. memset(word, 0, ARRAY_SIZE(word));
  8743. }
  8744. fclose(fptr1);
  8745. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8746. }
  8747. //Check TxDefaultProfile_0.json exit
  8748. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8749. {
  8750. i = 0;
  8751. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8752. //Check Charging Profile Count
  8753. while(fscanf(fptr1, "%s", word) != EOF)
  8754. {
  8755. //DEBUG_INFO("word=%s\n",word);
  8756. if(strstr(word, "chargingProfileId")!= NULL)
  8757. {
  8758. //DEBUG_INFO("test chargingProfileId \n");
  8759. n_chargingProfile = n_chargingProfile + 1;
  8760. i = i + 1;
  8761. //DEBUG_INFO("chargingProfileId Found\n");
  8762. }
  8763. memset(word, 0, ARRAY_SIZE(word));
  8764. }
  8765. fclose(fptr1);
  8766. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8767. }
  8768. //Check TxDefaultProfile_%d.json
  8769. for(int j=1; j <= gunTotalNumber; j++)
  8770. {
  8771. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8772. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8773. if((access(fnametemp,F_OK))!=-1)
  8774. {
  8775. i = 0;
  8776. fptr1 = fopen(fnametemp, "r");
  8777. //Check Charging Profile Count
  8778. while(fscanf(fptr1, "%s", word) != EOF)
  8779. {
  8780. //DEBUG_INFO("word=%s\n",word);
  8781. if(strstr(word, "chargingProfileId")!= NULL)
  8782. {
  8783. //DEBUG_INFO("test chargingProfileId \n");
  8784. n_chargingProfile = n_chargingProfile + 1;
  8785. i = i + 1;
  8786. //DEBUG_INFO("chargingProfileId Found\n");
  8787. }
  8788. memset(word, 0, ARRAY_SIZE(word));
  8789. }
  8790. fclose(fptr1);
  8791. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8792. }
  8793. }
  8794. //Check TxProfile_%d.json
  8795. for(int j=1; j <= gunTotalNumber; j++)
  8796. {
  8797. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8798. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8799. if((access(fnametemp,F_OK))!=-1)
  8800. {
  8801. i = 0;
  8802. fptr1 = fopen(fnametemp, "r");
  8803. //Check Charging Profile Count
  8804. while(fscanf(fptr1, "%s", word) != EOF)
  8805. {
  8806. //DEBUG_INFO("word=%s\n",word);
  8807. if(strstr(word, "chargingProfileId")!= NULL)
  8808. {
  8809. //DEBUG_INFO("test chargingProfileId \n");
  8810. n_chargingProfile = n_chargingProfile + 1;
  8811. i = i + 1;
  8812. //DEBUG_INFO("chargingProfileId Found\n");
  8813. }
  8814. memset(word, 0, ARRAY_SIZE(word));
  8815. }
  8816. fclose(fptr1);
  8817. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8818. }
  8819. }
  8820. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8821. {
  8822. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8823. goto end;
  8824. }
  8825. }
  8826. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8827. //**********************************Write to File********************************************************/
  8828. FILE *infile;
  8829. FILE *outfile;
  8830. // open file for writing
  8831. infile = fopen (filename, "r");
  8832. outfile = fopen (tempfile, "w");
  8833. int d =0;
  8834. d = fgetc(infile);
  8835. //DEBUG_INFO("d:%d\n",d);
  8836. rewind(infile);
  8837. //*璉 瘚 辣蝏     1嚗   0 */
  8838. if(d == EOF)
  8839. {
  8840. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8841. fprintf(outfile,"%s\n",payload);
  8842. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8843. fclose(infile);
  8844. fclose(outfile);
  8845. sprintf(rmFileCmd,"rm -f %s",filename);
  8846. system(rmFileCmd);
  8847. rename(tempfile, filename);
  8848. sleep(1);
  8849. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8850. //system(rmFileCmd);
  8851. }
  8852. else
  8853. {
  8854. char buf[1000]={0};
  8855. int ChargingProfileAdded = FALSE;
  8856. while (fgets(buf, sizeof(buf), infile) != NULL)
  8857. {
  8858. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8859. //*************************tempconnectorIdInt*********************************/
  8860. loc = strstr(buf, "connectorId");
  8861. c = 0;
  8862. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8863. while (loc[strlen("connectorId")+2+c] != ',')
  8864. {
  8865. sstr[c] = loc[strlen("connectorId")+2+c];
  8866. c++;
  8867. }
  8868. sstr[c] = '\0';
  8869. tempconnectorIdInt = atoi(sstr);
  8870. //*************************tempchargingProfileIdInt*********************************/
  8871. loc = strstr(buf, "chargingProfileId");
  8872. c = 0;
  8873. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8874. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8875. {
  8876. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8877. c++;
  8878. }
  8879. sstr[c] = '\0';
  8880. tempchargingProfileIdInt = atoi(sstr);
  8881. //*************************tempstackLevelInt*********************************/
  8882. loc = strstr(buf, "stackLevel");
  8883. c = 0;
  8884. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8885. while (loc[strlen("stackLevel")+2+c] != ',')
  8886. {
  8887. sstr[c] = loc[strlen("stackLevel")+2+c];
  8888. c++;
  8889. }
  8890. sstr[c] = '\0';
  8891. tempstackLevelInt = atoi(sstr);
  8892. //*************************tempchargingProfilePurposeStr*********************************/
  8893. loc = strstr(payload, "chargingProfilePurpose");
  8894. c = 0;
  8895. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8896. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8897. {
  8898. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8899. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8900. c++;
  8901. }
  8902. sstr[c] = '\0';
  8903. strcpy(tempchargingProfilePurposeStr,sstr);
  8904. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8905. {
  8906. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8907. {
  8908. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8909. if(ChargingProfileAdded == FALSE)
  8910. {
  8911. fprintf(outfile,"%s\n",payload);
  8912. ChargingProfileAdded = TRUE;
  8913. }
  8914. }
  8915. else
  8916. {
  8917. if(tempstackLevelInt < stackLevelInt)
  8918. {
  8919. if(ChargingProfileAdded == FALSE)
  8920. {
  8921. fprintf(outfile,"%s\n",payload);
  8922. ChargingProfileAdded = TRUE;
  8923. fprintf(outfile,"%s\n",buf);
  8924. }
  8925. else
  8926. {
  8927. fprintf(outfile,"%s\n",buf);
  8928. }
  8929. }
  8930. else
  8931. {
  8932. if(ChargingProfileAdded == FALSE)
  8933. {
  8934. fprintf(outfile,"%s\n",buf);
  8935. fprintf(outfile,"%s\n",payload);
  8936. ChargingProfileAdded = TRUE;
  8937. }
  8938. else
  8939. {
  8940. fprintf(outfile,"%s\n",buf);
  8941. }
  8942. }
  8943. }
  8944. }
  8945. else
  8946. {
  8947. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8948. {
  8949. if(ChargingProfileAdded == FALSE)
  8950. {
  8951. fprintf(outfile,"%s\n",payload);
  8952. ChargingProfileAdded = TRUE;
  8953. fprintf(outfile,"%s\n",buf);
  8954. }
  8955. else
  8956. {
  8957. fprintf(outfile,"%s\n",buf);
  8958. }
  8959. }
  8960. else if(tempstackLevelInt < stackLevelInt)
  8961. {
  8962. if(ChargingProfileAdded == FALSE)
  8963. {
  8964. fprintf(outfile,"%s\n",payload);
  8965. ChargingProfileAdded = TRUE;
  8966. fprintf(outfile,"%s\n",buf);
  8967. }
  8968. else
  8969. {
  8970. fprintf(outfile,"%s\n",buf);
  8971. }
  8972. }
  8973. else
  8974. {
  8975. if(ChargingProfileAdded == FALSE)
  8976. {
  8977. fprintf(outfile,"%s\n",buf);
  8978. fprintf(outfile,"%s\n",payload);
  8979. ChargingProfileAdded = TRUE;
  8980. }
  8981. else
  8982. {
  8983. fprintf(outfile,"%s\n",buf);
  8984. }
  8985. }
  8986. }
  8987. } // end of while loop
  8988. fclose(infile);
  8989. fclose(outfile);
  8990. sprintf(rmFileCmd,"rm -f %s",filename);
  8991. system(rmFileCmd);
  8992. rename(tempfile, filename);
  8993. sleep(1);
  8994. result = TRUE;
  8995. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8996. }
  8997. end:
  8998. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8999. return result;
  9000. return result;
  9001. }
  9002. int handleTriggerMessageRequest(char *uuid, char *payload)
  9003. {
  9004. mtrace();
  9005. int result = FAIL;
  9006. int connectorIdIsNULL = FALSE;
  9007. int connectorIdInt =0;
  9008. char sstr[40]={0},sstrtemp[100]={ 0 };
  9009. char requestedMessagestr[40]={0};
  9010. char comfirmstr[20]={0};
  9011. int c = 0;
  9012. char *loc;
  9013. DEBUG_INFO("handleTriggerMessageRequest\n");
  9014. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9015. strcpy(sstrtemp, stringtrimspace(payload));
  9016. c = 0;
  9017. loc = strstr(sstrtemp, "requestedMessage");
  9018. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9019. {
  9020. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9021. c++;
  9022. }
  9023. sstr[c] = '\0';
  9024. strcpy(requestedMessagestr, sstr);
  9025. c = 0;
  9026. loc = strstr(sstrtemp, "connectorId");
  9027. if(loc == NULL)
  9028. {
  9029. connectorIdIsNULL = TRUE;
  9030. }
  9031. else
  9032. {
  9033. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9034. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9035. {
  9036. sstr[c] = loc[strlen("connectorId")+2+c];
  9037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9038. c++;
  9039. }
  9040. sstr[c] = '\0';
  9041. connectorIdInt = atoi(sstr);
  9042. }
  9043. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9044. {
  9045. //connectorIdInt = json_object_get_int(connectorId);
  9046. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9047. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9048. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9049. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9050. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9051. }
  9052. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9053. {
  9054. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9055. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9056. return TRUE;
  9057. }
  9058. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9059. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9060. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9061. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9062. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9063. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9064. {
  9065. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9066. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9067. return TRUE;
  9068. }
  9069. else
  9070. {
  9071. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9072. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9073. }
  9074. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9075. {
  9076. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9077. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9078. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9079. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9080. {
  9081. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9082. }
  9083. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9084. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9085. }
  9086. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9087. {
  9088. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9089. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9090. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9091. }
  9092. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9093. {
  9094. sendBootNotificationRequest();
  9095. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9096. }
  9097. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9098. {
  9099. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9100. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9101. }
  9102. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9103. {
  9104. if(connectorIdIsNULL == FALSE)
  9105. {
  9106. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9107. {
  9108. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9109. sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9110. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9111. }
  9112. }
  9113. else
  9114. {
  9115. for(int idx=0;idx< gunTotalNumber;idx++)
  9116. {
  9117. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9118. sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9119. }
  9120. }
  9121. }
  9122. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9123. {
  9124. if(connectorIdIsNULL == FALSE)
  9125. {
  9126. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9127. {
  9128. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9129. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9130. }
  9131. }
  9132. else
  9133. {
  9134. for(int idx=0;idx< gunTotalNumber;idx++)
  9135. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9136. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9137. }
  9138. }
  9139. return result;
  9140. }
  9141. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9142. {
  9143. mtrace();
  9144. int result = FAIL;
  9145. char sstr[6]={0},sstrtemp[50]={ 0 };
  9146. int connectorIdInt =0;
  9147. char comfirmstr[20]={0};
  9148. int c = 0;
  9149. int tempIndex = 0;
  9150. char *loc;
  9151. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9152. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9153. strcpy(sstrtemp, stringtrimspace(payload));
  9154. c = 0;
  9155. loc = strstr(sstrtemp, "connectorId");
  9156. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9157. while (loc[strlen("connectorId")+2+c] != '}')
  9158. {
  9159. sstr[c] = loc[strlen("connectorId")+2+c];
  9160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9161. c++;
  9162. }
  9163. sstr[c] = '\0';
  9164. connectorIdInt = atoi(sstr);
  9165. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9166. if(gunTotalNumber == 0)
  9167. {
  9168. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9169. goto end;
  9170. }
  9171. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9172. {
  9173. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9174. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9175. goto end;
  9176. }
  9177. else
  9178. {
  9179. //check Transaction active
  9180. if(gunType[connectorIdInt-1] == 'J')
  9181. {
  9182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9183. {
  9184. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9185. }
  9186. else
  9187. {
  9188. tempIndex = connectorIdInt -1;
  9189. }
  9190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9191. {
  9192. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9193. {
  9194. //stop Transaction
  9195. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9196. }
  9197. }
  9198. }
  9199. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9200. {
  9201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9202. {
  9203. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9204. }
  9205. else
  9206. {
  9207. tempIndex = connectorIdInt -1;
  9208. }
  9209. for (int index = 0; index < CCS_QUANTITY; index++)
  9210. {
  9211. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9212. {
  9213. //stop Transaction
  9214. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9215. }
  9216. }
  9217. }
  9218. else if(gunType[connectorIdInt-1] == 'G')
  9219. {
  9220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9221. {
  9222. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9223. }
  9224. else
  9225. {
  9226. tempIndex = connectorIdInt -1;
  9227. }
  9228. for (int index = 0; index < GB_QUANTITY; index++)
  9229. {
  9230. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9231. {
  9232. //stop Transaction
  9233. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9234. }
  9235. }
  9236. }
  9237. else
  9238. {
  9239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9240. {
  9241. tempIndex = 2;
  9242. }
  9243. else
  9244. {
  9245. tempIndex = connectorIdInt-1;
  9246. }
  9247. for (int index = 0; index < AC_QUANTITY; index++)
  9248. {
  9249. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9250. {
  9251. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9252. }
  9253. }
  9254. }
  9255. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9256. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9257. result = TRUE;
  9258. return result;
  9259. }
  9260. end:
  9261. //json_object_put(obj); --- remove temporally
  9262. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9263. return result;
  9264. }
  9265. static char UpdateFirmwarepayloadData[300]={0};
  9266. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9267. {
  9268. mtrace();
  9269. int result = FAIL;
  9270. pthread_t t;
  9271. sendUpdateFirmwareConfirmation(uuid);
  9272. memset(UpdateFirmwarepayloadData, 0, 300);
  9273. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9274. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9275. ////pthread_join(t, NULL); //
  9276. //pthread_detach(t);
  9277. //sendUpdateFirmwareConfirmation(uuid);
  9278. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9279. return result;
  9280. }
  9281. void *UpdateFirmwareProcess(void *data)
  9282. {
  9283. pthread_detach(pthread_self());
  9284. mtrace();
  9285. int retriesInt =0, retryIntervalInt=0;
  9286. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9287. int port=0;
  9288. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9289. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9290. //char comfirmstr[20];
  9291. int isSuccess = 0;
  9292. char ftpbuf[200];
  9293. char temp[100];
  9294. char * pch;
  9295. int retriesISNULL=FALSE;
  9296. int retryInterval=FALSE;
  9297. int c = 0;
  9298. //int i = 0;
  9299. char *loc;
  9300. char sstr[300]={ 0 };
  9301. char str[300]={ 0 };
  9302. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9303. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9304. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9305. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9306. //***************location **************/
  9307. loc = strstr(str, "location");
  9308. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9309. c = 0;
  9310. while (loc[3+strlen("location")+c] != '\"')
  9311. {
  9312. sstr[c] = loc[3+strlen("location")+c];
  9313. c++;
  9314. }
  9315. sstr[c] = '\0';
  9316. strcpy(locationstr, sstr);
  9317. //***************retries**************/
  9318. c = 0;
  9319. loc = strstr(str, "retries");
  9320. if(loc == NULL)
  9321. {
  9322. retriesISNULL=TRUE;
  9323. }
  9324. else
  9325. {
  9326. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9327. while (loc[strlen("retries")+2+c] != ',')
  9328. {
  9329. sstr[c] = loc[strlen("retries")+2+c];
  9330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9331. c++;
  9332. }
  9333. sstr[c] = '\0';
  9334. }
  9335. if(retriesISNULL == FALSE)
  9336. {
  9337. retriesInt = atoi(sstr);
  9338. }
  9339. //***************retrieveDate **************/
  9340. loc = strstr(str, "retrieveDate");
  9341. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9342. c = 0;
  9343. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9344. {
  9345. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9346. c++;
  9347. }
  9348. sstr[c] = '\0';
  9349. strcpy(retrieveDatestr, sstr);
  9350. //***************retryInterval **************/
  9351. c = 0;
  9352. loc = strstr(str, "retryInterval");
  9353. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9354. if(loc == NULL)
  9355. {
  9356. retryInterval=TRUE;
  9357. }
  9358. else
  9359. {
  9360. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9361. {
  9362. sstr[c] = loc[strlen("retryInterval")+2+c];
  9363. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9364. c++;
  9365. }
  9366. sstr[c] = '\0';
  9367. }
  9368. if(retryInterval==FALSE)
  9369. {
  9370. retryIntervalInt = atoi(sstr);
  9371. }
  9372. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9373. memset(path, 0, ARRAY_SIZE(path));
  9374. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9375. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9376. if(strncmp(locationstr,"http", 4) == 0)
  9377. {
  9378. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9379. protocol, host, path);
  9380. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9381. // protocol, user, password, host, path);
  9382. sprintf(ftppath,"/%s", path);
  9383. //DEBUG_INFO("protocol =%s\n",protocol);
  9384. //DEBUG_INFO("host =%s\n",host);
  9385. //DEBUG_INFO("path =%s\n",path);
  9386. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9387. int ftppathlen=strlen(ftppath);
  9388. int i=1;
  9389. char filenametemp[50];
  9390. while(i < ftppathlen)
  9391. {
  9392. int len=ftppathlen-i;
  9393. if(ftppath[len]== 47) // '/' ascll code: 47
  9394. {
  9395. DEBUG_INFO("compare '/' all right\n");
  9396. break;
  9397. }
  9398. i=i+1;
  9399. }
  9400. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9401. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9402. filenametemp[i+1] = 0;
  9403. do
  9404. {
  9405. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9406. sleep(retryIntervalInt);
  9407. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9408. if(!isSuccess)
  9409. {
  9410. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9411. }
  9412. else
  9413. {
  9414. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9415. }
  9416. }
  9417. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9418. {
  9419. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9420. memset(temp, 0, ARRAY_SIZE(temp));
  9421. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9422. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9423. int ftppathlen=strlen(ftpbuf);
  9424. int i=1;
  9425. char filenametemp[50];
  9426. while(i < ftppathlen)
  9427. {
  9428. int len=ftppathlen-i;
  9429. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9430. {
  9431. DEBUG_INFO(" compare '/' all right\n");
  9432. break;
  9433. }
  9434. i=i+1;
  9435. }
  9436. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9437. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9438. filenametemp[i+1] = 0;
  9439. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9440. pch=strchr(temp,'@');
  9441. if(pch==NULL)
  9442. {
  9443. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9444. protocol, host, &port, path);
  9445. strcpy(user,"anonymous");
  9446. strcpy(password,"");
  9447. }
  9448. else
  9449. {
  9450. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9451. protocol, user, password, host, &port, path);
  9452. }
  9453. sscanf(host,"%[^/]%s",host1, path1);
  9454. sprintf(ftppath,"%s", path1);
  9455. //DEBUG_INFO("protocol =%s\n",protocol);
  9456. //DEBUG_INFO("user =%s\n",user);
  9457. //DEBUG_INFO("password =%s\n",password);
  9458. //DEBUG_INFO("host1 =%s\n",host1);
  9459. //DEBUG_INFO("port =%d\n",port);
  9460. //DEBUG_INFO("path1 =%s\n",path1);
  9461. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9462. //ftpFile(host, user, password, port, ftppath, fname);
  9463. //download firmware pthred
  9464. if(port == 0)
  9465. {
  9466. port = 21;
  9467. }
  9468. do
  9469. {
  9470. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9471. sleep(retryIntervalInt);
  9472. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9473. if(!isSuccess)
  9474. {
  9475. //BulldogUtil.sleepMs(interval*1000);
  9476. DEBUG_INFO("Update firmware request and download file fail.\n");
  9477. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9478. }
  9479. else
  9480. {
  9481. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9482. }
  9483. }
  9484. else
  9485. {
  9486. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9487. }
  9488. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9489. pthread_exit(NULL);
  9490. }
  9491. //==========================================
  9492. // Handle server response routine
  9493. //==========================================
  9494. void handleAuthorizeResponse(char *payload, int gun_index)
  9495. {
  9496. mtrace();
  9497. char expiryDatestr[30]={0};
  9498. char parentIdTagstr[20]={0};
  9499. char statusstr[20]={0};
  9500. char expiryDatestrtemp[30]={0};
  9501. char parentIdTagstrtemp[20]={0};
  9502. char IdTagstrtemp[20]={0};
  9503. char statusstrtemp[20]={0};
  9504. int expiryDateISNULL=FALSE;
  9505. int parentIdTagISNULL=FALSE;
  9506. char sstr[160]={0};
  9507. char* filename = AuthorizationCache_JSON;
  9508. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9509. char *loc;
  9510. int resultRename=0;
  9511. int responseIdTagInfoAsZero= 0;
  9512. char rmFileCmd[50]={0};
  9513. DEBUG_INFO("handleAuthorizeResponse...\n");
  9514. json_object *Authorize;
  9515. Authorize = json_tokener_parse(payload);
  9516. if(!is_error(Authorize))
  9517. {
  9518. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9519. {
  9520. // Required data
  9521. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9522. // Optional data
  9523. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9524. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9525. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9526. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9527. }
  9528. }
  9529. json_object_put(Authorize);
  9530. if(expiryDateISNULL == FALSE)
  9531. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9532. if(parentIdTagISNULL == FALSE)
  9533. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9534. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9535. //Update idTag information to authorization cache if supproted
  9536. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9537. {
  9538. if((access(filename,F_OK))!=-1)
  9539. {
  9540. printf("AuthorizationCache exist.\n");
  9541. }
  9542. else
  9543. {
  9544. printf("AuthorizationCache not exist\n");
  9545. FILE *log = fopen(filename, "w+");
  9546. if(log == NULL)
  9547. {
  9548. printf("log is NULL\n");
  9549. goto out;
  9550. }
  9551. else
  9552. {
  9553. fclose(log);
  9554. }
  9555. }
  9556. FILE *infile;
  9557. FILE *outfile;
  9558. // open file for writing
  9559. infile = fopen (filename, "r");
  9560. outfile = fopen (tempfile, "w");
  9561. int c;
  9562. c = fgetc(infile);
  9563. //DEBUG_INFO("c:%d\n",c);
  9564. rewind(infile);
  9565. if(c == EOF)
  9566. {
  9567. DEBUG_INFO("Orignal File is NULL\n");
  9568. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9569. {
  9570. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9571. }
  9572. else
  9573. {
  9574. strcpy(expiryDatestrtemp, "");
  9575. }
  9576. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9577. {
  9578. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9579. }
  9580. else
  9581. {
  9582. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9583. }
  9584. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9585. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9586. fclose(infile);
  9587. fclose(outfile);
  9588. sprintf(rmFileCmd,"rm -f %s",filename);
  9589. system(rmFileCmd);
  9590. resultRename = rename(tempfile, filename);
  9591. if(resultRename == 0)
  9592. {
  9593. printf("File renamed successfully");
  9594. }
  9595. else
  9596. {
  9597. printf("Error: unable to rename the file");
  9598. }
  9599. }
  9600. else
  9601. {
  9602. char buf[160]={0};
  9603. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9604. {
  9605. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9606. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9607. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9608. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9609. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9610. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9611. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9612. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9613. //------------------IdTag-----------------------
  9614. loc = strstr(buf, "idTag");
  9615. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9616. c = 0;
  9617. while (loc[3+strlen("idTag")+c] != '\"')
  9618. {
  9619. sstr[c] = loc[3+strlen("idTag")+c];
  9620. c++;
  9621. }
  9622. sstr[c] = '\0';
  9623. strcpy(IdTagstrtemp,sstr);
  9624. //*********************expiryDate***************/
  9625. loc = strstr(buf, "expiryDate");
  9626. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9627. c = 0;
  9628. while (loc[3+strlen("expiryDate")+c] != '\"')
  9629. {
  9630. sstr[c] = loc[3+strlen("expiryDate")+c];
  9631. c++;
  9632. }
  9633. sstr[c] = '\0';
  9634. strcpy(expiryDatestr,sstr);
  9635. //*********************parentIdTag***************/
  9636. loc = strstr(buf, "parentIdTag");
  9637. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9638. c = 0;
  9639. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9640. {
  9641. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9642. c++;
  9643. }
  9644. sstr[c] = '\0';
  9645. strcpy(parentIdTagstr,sstr);
  9646. //*********************status***************/
  9647. loc = strstr(buf, "status");
  9648. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9649. c = 0;
  9650. while (loc[3+strlen("status")+c] != '\"')
  9651. {
  9652. sstr[c] = loc[3+strlen("status")+c];
  9653. c++;
  9654. }
  9655. sstr[c] = '\0';
  9656. strcpy(statusstr,sstr);
  9657. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9658. {
  9659. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9660. responseIdTagInfoAsZero = 1;
  9661. }
  9662. else
  9663. {
  9664. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9665. }
  9666. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9667. {
  9668. //modify item
  9669. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9670. {
  9671. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9672. }
  9673. else
  9674. {
  9675. strcpy(expiryDatestrtemp, "");
  9676. }
  9677. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9678. {
  9679. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9680. }
  9681. else
  9682. {
  9683. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9684. }
  9685. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9686. }
  9687. else
  9688. {
  9689. //wrie original item
  9690. strcpy(expiryDatestrtemp, expiryDatestr);
  9691. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9692. strcpy(statusstrtemp, statusstr);
  9693. }
  9694. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9695. }
  9696. fclose(infile);
  9697. fclose(outfile);
  9698. sprintf(rmFileCmd,"rm -f %s",filename);
  9699. system(rmFileCmd);
  9700. resultRename = rename(tempfile, filename);
  9701. if(resultRename == 0)
  9702. {
  9703. DEBUG_INFO("File renamed successfully");
  9704. }
  9705. else
  9706. {
  9707. DEBUG_INFO("Error: unable to rename the file");
  9708. }
  9709. }
  9710. }
  9711. out:
  9712. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9713. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9714. authorizeRetryTimes = 0;
  9715. }
  9716. char * strtrimc( char * s )
  9717. {
  9718. char * p1 = s;
  9719. char * p2 = s;
  9720. while(*p1 != '\0')
  9721. {
  9722. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9723. {
  9724. if(*p1 != ',')
  9725. {
  9726. p1 ++;
  9727. }
  9728. else
  9729. {
  9730. break;
  9731. }
  9732. }
  9733. if(*p1 != ',')
  9734. {
  9735. * p2 ++ = *p1 ++;
  9736. //printf("p2=%s\n",p2);
  9737. }
  9738. else
  9739. {
  9740. break;
  9741. }
  9742. }
  9743. *p2 = '\0';
  9744. return (s);
  9745. }
  9746. void handleBootNotificationResponse(char *payload, int gun_index)
  9747. {
  9748. mtrace();
  9749. char statusStr[12]={0};
  9750. char currentTimeStr[30]={0};
  9751. int intervalInt = 0;
  9752. struct tm tp;
  9753. char buf[28]={0};
  9754. char timebuf[50]={0};
  9755. DEBUG_INFO("handleBootNotificationResponse...\n");
  9756. json_object *BootNotification;
  9757. BootNotification = json_tokener_parse(payload);
  9758. if(!is_error(BootNotification))
  9759. {
  9760. // Required data
  9761. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9762. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9763. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9764. }
  9765. json_object_put(BootNotification);
  9766. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9767. BootNotificationInterval = intervalInt;
  9768. HeartBeatWaitTime = intervalInt;
  9769. //write back to ShmOCPP16Data->BootNotification
  9770. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9771. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9772. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9773. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9774. {
  9775. server_sign = TRUE;
  9776. server_pending =FALSE;
  9777. }
  9778. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9779. {
  9780. server_pending = TRUE;
  9781. }
  9782. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9783. tp.tm_isdst = -1;
  9784. //time_t utc = mktime(&tp);
  9785. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9786. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9787. sprintf(timebuf,"date -s '%s'",buf);
  9788. system(timebuf);
  9789. srand(time(NULL));
  9790. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9791. //==============================================
  9792. // RTC sync
  9793. //==============================================
  9794. system("/sbin/hwclock -w --systohc");
  9795. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9796. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9797. }
  9798. void handleDataTransferResponse(char *payload, int gun_index)
  9799. {
  9800. char sstr[160]={0};//sstr[200]={ 0 };
  9801. int c = 0;
  9802. char *loc;
  9803. DEBUG_INFO("handleDataTransferResponse ...\n");
  9804. loc = strstr(payload, "status");
  9805. printf("loc=%s\n",loc);
  9806. c = 0;
  9807. while (loc[3+strlen("status")+c] != '\"')
  9808. {
  9809. sstr[c] = loc[3+strlen("status")+c];
  9810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9811. c++;
  9812. }
  9813. sstr[c] = '\0';
  9814. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9815. }
  9816. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9817. {
  9818. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9819. //struct json_object *obj;
  9820. // obj = json_tokener_parse(payload);
  9821. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9822. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9823. //No fields are defined.
  9824. }
  9825. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9826. {
  9827. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9828. //struct json_object *obj;
  9829. // obj = json_tokener_parse(payload);
  9830. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9831. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9832. //No fields are defined.
  9833. }
  9834. void handleHeartbeatResponse(char *payload, int gun_index)
  9835. {
  9836. mtrace();
  9837. struct tm tp;
  9838. char buf[28]={0};
  9839. char timebuf[50]={0};
  9840. DEBUG_INFO("handleHeartbeatResponse...\n");
  9841. json_object *Heartbeat;
  9842. Heartbeat = json_tokener_parse(payload);
  9843. if(!is_error(Heartbeat))
  9844. {
  9845. // Required data
  9846. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9847. }
  9848. json_object_put(BootNotification);
  9849. if(FirstHeartBeat == 0)
  9850. {
  9851. FirstHeartBeat = 1;
  9852. DEBUG_INFO("FirstHeartBeat \n");
  9853. }
  9854. HeartBeatWithNOResponse = 0;
  9855. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9856. tp.tm_isdst = -1;
  9857. //time_t utc = mktime(&tp);
  9858. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9859. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9860. sprintf(timebuf,"date -s '%s'",buf);
  9861. system(timebuf);
  9862. //==============================================
  9863. // RTC sync
  9864. //==============================================
  9865. system("/sbin/hwclock -w --systohc");
  9866. //===============================================
  9867. //Print Out HeartBeat log
  9868. //===============================================
  9869. {
  9870. double diff_t;
  9871. struct tm tp,tp1;
  9872. // BootNotification Receive Time
  9873. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9874. tp.tm_isdst = -1;
  9875. time_t BootNotificationReceiveTime = mktime(&tp);
  9876. //HeartBeat Receive Time
  9877. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9878. tp1.tm_isdst = -1;
  9879. time_t HeartBeatReceiveTime = mktime(&tp1);
  9880. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9881. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9882. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9883. {
  9884. HeartBeatCountPerHour = (int)diff_t / 3600;
  9885. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9886. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9887. }
  9888. }
  9889. }
  9890. void handleMeterValuesResponse(char *payload, int gun_index)
  9891. {
  9892. mtrace();
  9893. DEBUG_INFO("handleMeterValuesResponse...\n");
  9894. }
  9895. void handleStartTransactionResponse(char *payload, int gun_index)
  9896. {
  9897. mtrace();
  9898. //int transactionIdInt = 0;
  9899. FILE *outfile;
  9900. char data[100]={0};
  9901. DEBUG_INFO("handleStartTransactionResponse...\n");
  9902. json_object *StartTransaction;
  9903. StartTransaction = json_tokener_parse(payload);
  9904. if(!is_error(StartTransaction))
  9905. {
  9906. // Required data
  9907. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9908. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9909. // Optional data
  9910. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9911. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9912. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9913. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9914. }
  9915. json_object_put(StartTransaction);
  9916. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9917. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9918. //-----------Start : write to the Queue TransactionId file -----------------//
  9919. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9920. {}
  9921. else
  9922. {
  9923. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9924. if(log == NULL)
  9925. {
  9926. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9927. return ;
  9928. }
  9929. else
  9930. {
  9931. fclose(log);
  9932. }
  9933. }
  9934. // open file for writing
  9935. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9936. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9937. {
  9938. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9939. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9940. fputs(data, outfile);
  9941. fclose (outfile);
  9942. }
  9943. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9944. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9945. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9946. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9947. }
  9948. void handleStatusNotificationResponse(char *payload, int gun_index)
  9949. {
  9950. mtrace();
  9951. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9952. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9953. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9954. }
  9955. void handleStopTransactionnResponse(char *payload, int gun_index)
  9956. {
  9957. mtrace();
  9958. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9959. json_object *StopTransaction;
  9960. StopTransaction = json_tokener_parse(payload);
  9961. if(!is_error(StopTransaction))
  9962. {
  9963. // Optional data
  9964. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9965. {
  9966. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9967. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9969. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9970. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9971. }
  9972. }
  9973. json_object_put(StopTransaction);
  9974. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9975. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9976. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9977. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9978. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9979. }
  9980. //==========================================
  9981. // Handle Error routine
  9982. //==========================================
  9983. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9984. {
  9985. mtrace();
  9986. #ifdef SystemLogMessage
  9987. DEBUG_INFO("errorCode: %s\n", errorCode);
  9988. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9989. DEBUG_INFO("errorDetails: %s\n", payload);
  9990. #endif
  9991. }
  9992. //===============================================
  9993. // Common routine
  9994. //===============================================
  9995. int initialConfigurationTable(void)
  9996. {
  9997. //clock_t start_t, end_t, total_t;
  9998. FILE *fp;
  9999. FILE *outfile;
  10000. char str[200]={0};
  10001. char sstr[100]={0};
  10002. int c = 0;
  10003. char *loc;
  10004. DEBUG_INFO("initialConfigurationTable...\n");
  10005. //start_t = clock();
  10006. //printf("Starting of the program, start_t = %ld\n", start_t);
  10007. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10008. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10009. {
  10010. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10011. if(outfile == NULL)
  10012. {
  10013. DEBUG_INFO("Error opening file\n");
  10014. return FALSE;
  10015. }
  10016. /*Core Profile*/
  10017. //AllowOfflineTxForUnknownId
  10018. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10022. //AuthorizationCacheEnabled
  10023. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10027. //AuthorizeRemoteTxRequests
  10028. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10032. //BlinkRepeat
  10033. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10037. //ClockAlignedDataInterval
  10038. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10042. //ConnectionTimeOut
  10043. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10047. //GetConfigurationMaxKeys
  10048. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10052. // HeartbeatInterval
  10053. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10057. // LightIntensity
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10062. // LocalAuthorizeOffline
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10067. // LocalPreAuthorize
  10068. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10072. // MaxEnergyOnInvalidId
  10073. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10076. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10078. // MeterValuesAlignedData
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10083. else
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10086. // MeterValuesAlignedDataMaxLength
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10091. else
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10094. // MeterValuesSampledData
  10095. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10099. else
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10102. // MeterValuesSampledDataMaxLength
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10107. else
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10110. // MeterValueSampleInterval
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10115. // MinimumStatusDuration
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10119. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10121. // NumberOfConnectors
  10122. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10125. {
  10126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10127. }
  10128. else
  10129. {
  10130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10131. }
  10132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10133. // ResetRetries
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10138. // ConnectorPhaseRotation
  10139. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10143. // ConnectorPhaseRotationMaxLength
  10144. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10148. // StopTransactionOnEVSideDisconnect
  10149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10153. // StopTransactionOnInvalidId
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10158. // StopTxnAlignedData
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10163. // StopTxnAlignedDataMaxLength
  10164. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10168. // StopTxnSampledData
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10173. else
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10176. // StopTxnSampledDataMaxLength
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10180. {
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10182. }
  10183. else
  10184. {
  10185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10186. }
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10188. // SupportedFeatureProfiles
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10193. // SupportedFeatureProfilesMaxLength
  10194. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10198. // TransactionMessageAttempts
  10199. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10202. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10204. // TransactionMessageRetryInterval
  10205. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10208. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10210. // UnlockConnectorOnEVSideDisconnect
  10211. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10215. // WebSocketPingInterval
  10216. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10220. // QueueOffLineStartTransactionMessage
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10225. //* Local Auth List Management Profile*/
  10226. #if 0
  10227. //For OCTT Test Case
  10228. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10231. #endif
  10232. #if 1
  10233. //LocalAuthListEnabled
  10234. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10238. #endif
  10239. //LocalAuthListMaxLength
  10240. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10244. //SendLocalListMaxLength
  10245. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10249. //ReserveConnectorZeroSupported
  10250. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10254. //* Smart Charging Profile */
  10255. //ChargeProfileMaxStackLevel
  10256. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10260. // ChargingScheduleAllowedChargingRateUnit
  10261. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10265. // ChargingScheduleMaxPeriods
  10266. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10270. // ConnectorSwitch3to1PhaseSupported
  10271. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10275. // MaxChargingProfilesInstalled
  10276. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10280. fclose(outfile);
  10281. }
  10282. else
  10283. {
  10284. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10285. char keystr[60]={0};
  10286. char readonlystr[10]={0};
  10287. char valuestr[100]={0};
  10288. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10289. if(fp == NULL) {
  10290. DEBUG_INFO("Error opening file");
  10291. return FALSE;
  10292. }
  10293. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10294. {
  10295. //DEBUG_INFO("Get Configuration \n");
  10296. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10297. //*************************key*********************************/
  10298. loc = strstr(str, "key");
  10299. c = 0;
  10300. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10301. while (loc[strlen("key")+3+c] != '\"')
  10302. {
  10303. sstr[c] = loc[strlen("key")+3+c];
  10304. c++;
  10305. }
  10306. sstr[c] = '\0';
  10307. strcpy(keystr,sstr);
  10308. //*************************readonly*********************************/
  10309. loc = strstr(str, "readonly");
  10310. c = 0;
  10311. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10312. while (loc[strlen("readonly")+2+c] != ',')
  10313. {
  10314. sstr[c] = loc[strlen("readonly")+2+c];
  10315. c++;
  10316. }
  10317. sstr[c] = '\0';
  10318. strcpy(readonlystr,sstr);
  10319. //*************************value*********************************/
  10320. loc = strstr(str, "value");
  10321. c = 0;
  10322. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10323. while (loc[strlen("value")+3+c] != '\"')
  10324. {
  10325. sstr[c] = loc[strlen("value")+3+c];
  10326. c++;
  10327. }
  10328. sstr[c] = '\0';
  10329. strcpy(valuestr,sstr);
  10330. // DEBUG_INFO("keystr=%s\n",keystr);
  10331. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10332. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10333. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10334. {
  10335. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10338. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10339. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10340. }
  10341. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10342. {
  10343. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10344. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10346. }
  10347. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10348. {
  10349. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10351. }
  10352. if(strcmp(keystr, "BlinkRepeat") == 0)
  10353. {
  10354. //Charger.BlinkRepeat = Integer.parseInt(value);
  10355. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10357. }
  10358. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10359. {
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10362. }
  10363. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10364. {
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10367. }
  10368. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10369. {
  10370. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10372. }
  10373. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10374. {
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10377. HeartBeatWaitTime = atoi(valuestr);
  10378. }
  10379. if(strcmp(keystr, "LightIntensity") == 0)
  10380. {
  10381. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10383. }
  10384. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10385. {
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10388. }
  10389. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10390. {
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10393. }
  10394. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10395. {
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10398. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10399. }
  10400. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10401. {
  10402. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10404. }
  10405. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10406. {
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10409. }
  10410. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10411. {
  10412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10414. }
  10415. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10416. {
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10419. }
  10420. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10421. {
  10422. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10424. }
  10425. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10426. {
  10427. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10429. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10430. }
  10431. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10432. {
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10435. }
  10436. if(strcmp(keystr, "ResetRetries") == 0)
  10437. {
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10440. }
  10441. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10442. {
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10445. }
  10446. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10447. {
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10450. }
  10451. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10452. {
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10455. }
  10456. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10457. {
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10460. }
  10461. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10462. {
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10465. }
  10466. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10467. {
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10470. }
  10471. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10475. }
  10476. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10480. }
  10481. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10485. }
  10486. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10490. }
  10491. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10492. {
  10493. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10495. TransactionMessageAttemptsValue = atoi(valuestr);
  10496. }
  10497. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10501. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10502. }
  10503. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10504. {
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10507. }
  10508. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10509. {
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10512. }
  10513. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10514. {
  10515. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10517. }
  10518. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10519. {
  10520. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10522. }
  10523. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10527. }
  10528. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10529. {
  10530. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10532. }
  10533. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10534. {
  10535. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10537. }
  10538. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10539. {
  10540. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10542. }
  10543. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10547. }
  10548. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10549. {
  10550. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10552. }
  10553. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10554. {
  10555. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10557. }
  10558. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10559. {
  10560. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10562. }
  10563. }
  10564. fclose(fp);
  10565. }
  10566. return 0;
  10567. }
  10568. void StoreConfigurationTable(void)
  10569. {
  10570. FILE *outfile;
  10571. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10572. if(outfile == NULL)
  10573. {
  10574. DEBUG_INFO("Error opening file");
  10575. return ;
  10576. }
  10577. /*Core Profile*/
  10578. //AllowOfflineTxForUnknownId
  10579. /*
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10581. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10584. */
  10585. //DEBUG_INFO("data=%s\n",data);
  10586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10587. //AuthorizationCacheEnabled
  10588. /*
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10592. */
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10594. //AuthorizeRemoteTxRequests
  10595. /*
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10599. */
  10600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10601. //BlinkRepeat
  10602. /*
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10606. */
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10608. //ClockAlignedDataInterval
  10609. /*
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10613. */
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10615. //ConnectionTimeOut
  10616. /*
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10620. */
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10622. //GetConfigurationMaxKeys
  10623. /*
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10627. */
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10629. // HeartbeatInterval
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10634. */
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10636. // LightIntensity
  10637. /*
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10641. */
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10643. // LocalAuthorizeOffline
  10644. /*
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10648. */
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10650. // LocalPreAuthorize
  10651. /*
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10655. */
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10657. // MaxEnergyOnInvalidId
  10658. /*
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10662. */
  10663. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10665. // MeterValuesAlignedData
  10666. /*
  10667. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10670. */
  10671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10672. // MeterValuesAlignedDataMaxLength
  10673. /*
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10677. */
  10678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10679. // MeterValuesSampledData
  10680. /*
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10684. */
  10685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10686. // MeterValuesSampledDataMaxLength
  10687. /*
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10691. */
  10692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10693. // MeterValueSampleInterval
  10694. /*
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10698. */
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10700. // MinimumStatusDuration
  10701. /*
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10705. */
  10706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10707. // NumberOfConnectors
  10708. /*
  10709. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10711. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10712. {
  10713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10714. }
  10715. else
  10716. {
  10717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10718. }
  10719. */
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10721. // ResetRetries
  10722. /*
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10726. */
  10727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10728. // ConnectorPhaseRotation
  10729. /*
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10733. */
  10734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10735. // ConnectorPhaseRotationMaxLength
  10736. /*
  10737. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10740. */
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10742. // StopTransactionOnEVSideDisconnect
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10749. // StopTransactionOnInvalidId
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10754. */
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10756. // StopTxnAlignedData
  10757. /*
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10761. */
  10762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10763. // StopTxnAlignedDataMaxLength
  10764. /*
  10765. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10768. */
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10770. // StopTxnSampledData
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10775. */
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10777. // StopTxnSampledDataMaxLength
  10778. /*
  10779. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10782. */
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10784. // SupportedFeatureProfiles
  10785. /*
  10786. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10789. */
  10790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10791. // SupportedFeatureProfilesMaxLength
  10792. /*
  10793. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10796. */
  10797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10798. // TransactionMessageAttempts
  10799. /*
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10803. */
  10804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10805. // TransactionMessageRetryInterval
  10806. /*
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10810. */
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10812. // UnlockConnectorOnEVSideDisconnect
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10817. */
  10818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10819. // WebSocketPingInterval
  10820. /*
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10826. // QueueOffLineStartTransactionMessage
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10833. //* Local Auth List Management Profile*/
  10834. //LocalAuthListEnabled
  10835. /*
  10836. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10839. */
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10841. //LocalAuthListMaxLength
  10842. /*
  10843. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10846. */
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10848. //SendLocalListMaxLength
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10853. */
  10854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10855. //ReserveConnectorZeroSupported
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10862. //* Smart Charging Profile */
  10863. //ChargeProfileMaxStackLevel
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10870. // ChargingScheduleAllowedChargingRateUnit
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10877. // ChargingScheduleMaxPeriods
  10878. /*
  10879. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10882. */
  10883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10884. // ConnectorSwitch3to1PhaseSupported
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10891. // MaxChargingProfilesInstalled
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10896. */
  10897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10898. fclose(outfile);
  10899. }
  10900. void getKeyValue(char *keyReq)
  10901. {
  10902. int isEmpty = FALSE;
  10903. int isKnowKey = FALSE;
  10904. DEBUG_INFO("keyReq = %s\n", keyReq);
  10905. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10906. isEmpty = TRUE;
  10907. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10908. {
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10912. {
  10913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10914. }
  10915. else
  10916. {
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10918. }
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10920. isKnowKey = TRUE;
  10921. }
  10922. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10923. {
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10927. {
  10928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10929. }
  10930. else
  10931. {
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10933. }
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10935. isKnowKey = TRUE;
  10936. }
  10937. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10944. }
  10945. else
  10946. {
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10948. }
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10950. isKnowKey = TRUE;
  10951. }
  10952. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10959. }
  10960. else
  10961. {
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10963. }
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10965. isKnowKey = TRUE;
  10966. }
  10967. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10974. }
  10975. else
  10976. {
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10978. }
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10980. isKnowKey = TRUE;
  10981. }
  10982. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10989. }
  10990. else
  10991. {
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10993. }
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10995. isKnowKey = TRUE;
  10996. }
  10997. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11004. }
  11005. else
  11006. {
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11008. }
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11010. isKnowKey = TRUE;
  11011. }
  11012. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11019. }
  11020. else
  11021. {
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11023. }
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11025. isKnowKey = TRUE;
  11026. }
  11027. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11034. }
  11035. else
  11036. {
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11038. }
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11040. isKnowKey = TRUE;
  11041. }
  11042. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11049. }
  11050. else
  11051. {
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11053. }
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11055. isKnowKey = TRUE;
  11056. }
  11057. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11064. }
  11065. else
  11066. {
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11068. }
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11070. isKnowKey = TRUE;
  11071. }
  11072. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11079. }
  11080. else
  11081. {
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11083. }
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11085. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11086. isKnowKey = TRUE;
  11087. }
  11088. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11095. }
  11096. else
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11099. }
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11101. isKnowKey = TRUE;
  11102. }
  11103. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11110. }
  11111. else
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11114. }
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11116. isKnowKey = TRUE;
  11117. }
  11118. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11125. }
  11126. else
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11129. }
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11131. isKnowKey = TRUE;
  11132. }
  11133. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11140. }
  11141. else
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11144. }
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11146. isKnowKey = TRUE;
  11147. }
  11148. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11155. }
  11156. else
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11159. }
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11161. isKnowKey = TRUE;
  11162. }
  11163. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11170. }
  11171. else
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11174. }
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11176. isKnowKey = TRUE;
  11177. }
  11178. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11185. }
  11186. else
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11189. }
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11191. isKnowKey = TRUE;
  11192. }
  11193. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11200. }
  11201. else
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11204. }
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11206. isKnowKey = TRUE;
  11207. }
  11208. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11209. {
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11215. }
  11216. else
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11219. }
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11221. isKnowKey = TRUE;
  11222. }
  11223. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11224. {
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11230. }
  11231. else
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11234. }
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11236. isKnowKey = TRUE;
  11237. }
  11238. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11239. {
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11245. }
  11246. else
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11249. }
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11251. isKnowKey = TRUE;
  11252. }
  11253. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11254. {
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11260. }
  11261. else
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11264. }
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11266. isKnowKey = TRUE;
  11267. }
  11268. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11269. {
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11273. {
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11275. }
  11276. else
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11279. }
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11281. isKnowKey = TRUE;
  11282. }
  11283. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11284. {
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11290. }
  11291. else
  11292. {
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11294. }
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11296. isKnowKey = TRUE;
  11297. }
  11298. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11299. {
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11305. }
  11306. else
  11307. {
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11309. }
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11311. isKnowKey = TRUE;
  11312. }
  11313. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11314. {
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11320. }
  11321. else
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11324. }
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11326. isKnowKey = TRUE;
  11327. }
  11328. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11329. {
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11335. }
  11336. else
  11337. {
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11339. }
  11340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11341. isKnowKey = TRUE;
  11342. }
  11343. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11344. {
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11347. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11350. }
  11351. else
  11352. {
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11354. }
  11355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11356. isKnowKey = TRUE;
  11357. }
  11358. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11359. {
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11365. }
  11366. else
  11367. {
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11369. }
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11371. isKnowKey = TRUE;
  11372. }
  11373. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11380. }
  11381. else
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11384. }
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11386. isKnowKey = TRUE;
  11387. }
  11388. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11395. }
  11396. else
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11399. }
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11401. isKnowKey = TRUE;
  11402. }
  11403. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11410. }
  11411. else
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11414. }
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11416. isKnowKey = TRUE;
  11417. }
  11418. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11425. }
  11426. else
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11429. }
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11431. isKnowKey = TRUE;
  11432. }
  11433. #if 1
  11434. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11438. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11441. }
  11442. else
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11445. }
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11447. isKnowKey = TRUE;
  11448. }
  11449. #endif
  11450. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11454. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11457. }
  11458. else
  11459. {
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11461. }
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11463. isKnowKey = TRUE;
  11464. }
  11465. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11469. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11472. }
  11473. else
  11474. {
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11476. }
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11478. isKnowKey = TRUE;
  11479. }
  11480. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11484. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11487. }
  11488. else
  11489. {
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11491. }
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11493. isKnowKey = TRUE;
  11494. }
  11495. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11499. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11502. }
  11503. else
  11504. {
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11506. }
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11508. isKnowKey = TRUE;
  11509. }
  11510. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11514. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11517. }
  11518. else
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11521. }
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11523. isKnowKey = TRUE;
  11524. }
  11525. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11529. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11532. }
  11533. else
  11534. {
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11536. }
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11538. isKnowKey = TRUE;
  11539. }
  11540. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11544. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11547. }
  11548. else
  11549. {
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11551. }
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11553. isKnowKey = TRUE;
  11554. }
  11555. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11559. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11562. }
  11563. else
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11566. }
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11568. isKnowKey = TRUE;
  11569. }
  11570. //=========================================================
  11571. if(!isEmpty && !isKnowKey)
  11572. {
  11573. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11574. strcpy(unknownkey[UnknownKeynum], keyReq);
  11575. UnknownKeynum = UnknownKeynum + 1;
  11576. }
  11577. }
  11578. void processUnkownKey(void)
  11579. {
  11580. DEBUG_INFO("processUnkownKey...\n");
  11581. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11582. for(int index=0; index < UnknownKeynum; index++)
  11583. {
  11584. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11585. {
  11586. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11587. }
  11588. }
  11589. }
  11590. int setKeyValue(char *key, char *value)
  11591. {
  11592. int isSuccess = NotSupported;
  11593. int check_ascii=0;
  11594. char str[10]={0};
  11595. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11596. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11597. {
  11598. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11600. {
  11601. strcpy(str, (const char*)value);
  11602. for(int i = 0; str[i]; i++){
  11603. str[i] = tolower(str[i]);
  11604. }
  11605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11606. isSuccess = ConfigurationStatus_Accepted;
  11607. }
  11608. else
  11609. {
  11610. isSuccess = ConfigurationStatus_Rejected;
  11611. }
  11612. }
  11613. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11614. {
  11615. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11617. {
  11618. strcpy(str, (const char*)value);
  11619. for(int i = 0; str[i]; i++){
  11620. str[i] = tolower(str[i]);
  11621. }
  11622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11623. isSuccess = ConfigurationStatus_Accepted;
  11624. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11625. }
  11626. else
  11627. {
  11628. isSuccess = ConfigurationStatus_Rejected;
  11629. }
  11630. }
  11631. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11632. {
  11633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11634. {
  11635. strcpy(str, (const char*)value);
  11636. for(int i = 0; str[i]; i++)
  11637. {
  11638. str[i] = tolower(str[i]);
  11639. }
  11640. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11642. isSuccess = ConfigurationStatus_Accepted;
  11643. }
  11644. else
  11645. {
  11646. isSuccess = ConfigurationStatus_Rejected;
  11647. }
  11648. }
  11649. if(strcmp(key, "BlinkRepeat") == 0)
  11650. {
  11651. //Charger.BlinkRepeat = Integer.parseInt(value);
  11652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11653. {
  11654. check_ascii = value[0];
  11655. if( (check_ascii < 48) || (check_ascii > 57) )
  11656. {
  11657. isSuccess = ConfigurationStatus_Rejected;
  11658. }
  11659. else
  11660. {
  11661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11662. isSuccess = ConfigurationStatus_Accepted;
  11663. }
  11664. }
  11665. else
  11666. {
  11667. isSuccess = ConfigurationStatus_Rejected;
  11668. }
  11669. }
  11670. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11671. {
  11672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11673. {
  11674. check_ascii = value[0];
  11675. if( (check_ascii < 48) || (check_ascii > 57) )
  11676. {
  11677. isSuccess = ConfigurationStatus_Rejected;
  11678. }
  11679. else
  11680. {
  11681. if((atoi(value) == 0) || (atoi(value) >= 10))
  11682. {
  11683. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11685. isSuccess = ConfigurationStatus_Accepted;
  11686. }
  11687. else
  11688. isSuccess = ConfigurationStatus_Rejected;
  11689. }
  11690. }
  11691. else
  11692. {
  11693. isSuccess = ConfigurationStatus_Rejected;
  11694. }
  11695. }
  11696. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11697. {
  11698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11699. {
  11700. check_ascii = value[0];
  11701. if( (check_ascii < 48) || (check_ascii > 57) )
  11702. {
  11703. isSuccess = ConfigurationStatus_Rejected;
  11704. }
  11705. else
  11706. {
  11707. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11709. isSuccess = ConfigurationStatus_Accepted;
  11710. }
  11711. }
  11712. else
  11713. {
  11714. isSuccess = ConfigurationStatus_Rejected;
  11715. }
  11716. }
  11717. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11718. {
  11719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11720. {
  11721. check_ascii = value[0];
  11722. if( (check_ascii < 48) || (check_ascii > 57) )
  11723. {
  11724. isSuccess = ConfigurationStatus_Rejected;
  11725. }
  11726. else
  11727. {
  11728. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11730. isSuccess = ConfigurationStatus_Accepted;
  11731. }
  11732. }
  11733. else
  11734. {
  11735. isSuccess = ConfigurationStatus_Rejected;
  11736. }
  11737. }
  11738. if(strcmp(key, "HeartbeatInterval") == 0)
  11739. {
  11740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11741. {
  11742. check_ascii = value[0];
  11743. if( (check_ascii < 48) || (check_ascii > 57) )
  11744. {
  11745. isSuccess = ConfigurationStatus_Rejected;
  11746. }
  11747. else
  11748. {
  11749. if((atoi(value) == 0) || (atoi(value) >= 10))
  11750. {
  11751. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11753. HeartBeatWaitTime = atoi(value);
  11754. isSuccess = ConfigurationStatus_Accepted;
  11755. }
  11756. else
  11757. {
  11758. isSuccess = ConfigurationStatus_Rejected;
  11759. }
  11760. }
  11761. }
  11762. else
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. }
  11767. if(strcmp(key, "LightIntensity") == 0)
  11768. {
  11769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11770. {
  11771. check_ascii = value[0];
  11772. if( (check_ascii < 48) || (check_ascii > 57) )
  11773. {
  11774. isSuccess = ConfigurationStatus_Rejected;
  11775. }
  11776. else
  11777. {
  11778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11779. isSuccess = ConfigurationStatus_Accepted;
  11780. }
  11781. }
  11782. else
  11783. {
  11784. isSuccess = ConfigurationStatus_Rejected;
  11785. }
  11786. }
  11787. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11788. {
  11789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11790. {
  11791. strcpy(str, (const char*)value);
  11792. for(int i = 0; str[i]; i++)
  11793. {
  11794. str[i] = tolower(str[i]);
  11795. }
  11796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11797. isSuccess = ConfigurationStatus_Accepted;
  11798. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11799. }
  11800. else
  11801. {
  11802. isSuccess = ConfigurationStatus_Rejected;
  11803. }
  11804. }
  11805. if(strcmp(key, "LocalPreAuthorize") == 0)
  11806. {
  11807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11808. {
  11809. strcpy(str, (const char*)value);
  11810. for(int i = 0; str[i]; i++)
  11811. {
  11812. str[i] = tolower(str[i]);
  11813. }
  11814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11815. isSuccess = ConfigurationStatus_Accepted;
  11816. }
  11817. else
  11818. {
  11819. isSuccess = ConfigurationStatus_Rejected;
  11820. }
  11821. }
  11822. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11823. {
  11824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11825. {
  11826. check_ascii = value[0];
  11827. if( (check_ascii < 48) || (check_ascii > 57) )
  11828. {
  11829. isSuccess = ConfigurationStatus_Rejected;
  11830. }
  11831. else
  11832. {
  11833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11834. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11835. isSuccess = ConfigurationStatus_Accepted;
  11836. }
  11837. }
  11838. else
  11839. {
  11840. isSuccess = ConfigurationStatus_Rejected;
  11841. }
  11842. }
  11843. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11844. {
  11845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11846. {
  11847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11848. isSuccess = ConfigurationStatus_Accepted;
  11849. }
  11850. else
  11851. {
  11852. isSuccess = ConfigurationStatus_Rejected;
  11853. }
  11854. }
  11855. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11856. {
  11857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11858. {
  11859. check_ascii = value[0];
  11860. if( (check_ascii < 48) || (check_ascii > 57) )
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. else
  11865. {
  11866. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11868. isSuccess = ConfigurationStatus_Accepted;
  11869. }
  11870. }
  11871. else
  11872. {
  11873. isSuccess = ConfigurationStatus_Rejected;
  11874. }
  11875. }
  11876. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11877. {
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11879. {
  11880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11881. isSuccess = ConfigurationStatus_Accepted;
  11882. }
  11883. else
  11884. {
  11885. isSuccess = ConfigurationStatus_Rejected;
  11886. }
  11887. }
  11888. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11889. {
  11890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11891. {
  11892. check_ascii = value[0];
  11893. if( (check_ascii < 48) || (check_ascii > 57) )
  11894. {
  11895. isSuccess = ConfigurationStatus_Rejected;
  11896. }
  11897. else
  11898. {
  11899. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11901. isSuccess = ConfigurationStatus_Accepted;
  11902. }
  11903. }
  11904. else
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. }
  11909. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11910. {
  11911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11912. {
  11913. check_ascii = value[0];
  11914. if( (check_ascii < 48) || (check_ascii > 57) )
  11915. {
  11916. isSuccess = ConfigurationStatus_Rejected;
  11917. }
  11918. else
  11919. {
  11920. if((atoi(value) == 0) || (atoi(value) >= 10))
  11921. {
  11922. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11924. isSuccess = ConfigurationStatus_Accepted;
  11925. }
  11926. else
  11927. {
  11928. isSuccess = ConfigurationStatus_Rejected;
  11929. }
  11930. }
  11931. }
  11932. else
  11933. {
  11934. isSuccess = ConfigurationStatus_Rejected;
  11935. }
  11936. }
  11937. if(strcmp(key, "MinimumStatusDuration") == 0)
  11938. {
  11939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11940. {
  11941. check_ascii = value[0];
  11942. if( (check_ascii < 48) || (check_ascii > 57) )
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. else
  11947. {
  11948. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11949. {
  11950. isSuccess = ConfigurationStatus_Rejected;
  11951. }
  11952. else
  11953. {
  11954. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11956. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11957. isSuccess = ConfigurationStatus_Accepted;
  11958. }
  11959. }
  11960. }
  11961. else
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. }
  11966. if(strcmp(key, "NumberOfConnectors") == 0)
  11967. {
  11968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11969. {
  11970. check_ascii = value[0];
  11971. if( (check_ascii < 48) || (check_ascii > 57) )
  11972. {
  11973. isSuccess = ConfigurationStatus_Rejected;
  11974. }
  11975. else
  11976. {
  11977. //Charger.ResetRetries = Integer.parseInt(value);
  11978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11979. isSuccess = ConfigurationStatus_Accepted;
  11980. }
  11981. }
  11982. else
  11983. {
  11984. isSuccess = ConfigurationStatus_Rejected;
  11985. }
  11986. }
  11987. if(strcmp(key, "ResetRetries") == 0)
  11988. {
  11989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11990. {
  11991. check_ascii = value[0];
  11992. if( (check_ascii < 48) || (check_ascii > 57) )
  11993. {
  11994. isSuccess = ConfigurationStatus_Rejected;
  11995. }
  11996. else
  11997. {
  11998. //Charger.ResetRetries = Integer.parseInt(value);
  11999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12000. isSuccess = ConfigurationStatus_Accepted;
  12001. }
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12011. {
  12012. strcpy(str, (const char*)value);
  12013. for(int i = 0; str[i]; i++)
  12014. {
  12015. str[i] = tolower(str[i]);
  12016. }
  12017. if(strcmp(str, "notapplicable")== 0)
  12018. {
  12019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12020. isSuccess = ConfigurationStatus_Accepted;
  12021. }
  12022. else if(strcmp(str, "unknown")== 0)
  12023. {
  12024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12025. isSuccess = ConfigurationStatus_Accepted;
  12026. }
  12027. else if(strcmp(str, "rst")== 0)
  12028. {
  12029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12030. isSuccess = ConfigurationStatus_Accepted;
  12031. }
  12032. else if(strcmp(str, "rts")== 0)
  12033. {
  12034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12035. isSuccess = ConfigurationStatus_Accepted;
  12036. }
  12037. else if(strcmp(str, "srt")== 0)
  12038. {
  12039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12040. isSuccess = ConfigurationStatus_Accepted;
  12041. }
  12042. else if(strcmp(str, "str")== 0)
  12043. {
  12044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12045. isSuccess = ConfigurationStatus_Accepted;
  12046. }
  12047. else if(strcmp(str, "trs")== 0)
  12048. {
  12049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12050. isSuccess = ConfigurationStatus_Accepted;
  12051. }
  12052. else if(strcmp(str, "tsr")== 0)
  12053. {
  12054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12055. isSuccess = ConfigurationStatus_Accepted;
  12056. }
  12057. else
  12058. {
  12059. isSuccess = ConfigurationStatus_Rejected;
  12060. }
  12061. }
  12062. else
  12063. {
  12064. isSuccess = ConfigurationStatus_Rejected;
  12065. }
  12066. }
  12067. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12068. {
  12069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12070. {
  12071. check_ascii = value[0];
  12072. if( (check_ascii < 48) || (check_ascii > 57) )
  12073. {
  12074. isSuccess = ConfigurationStatus_Rejected;
  12075. }
  12076. else
  12077. {
  12078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12079. isSuccess = ConfigurationStatus_Accepted;
  12080. }
  12081. }
  12082. else
  12083. {
  12084. isSuccess = ConfigurationStatus_Rejected;
  12085. }
  12086. }
  12087. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12088. {
  12089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12090. {
  12091. strcpy(str, (const char*)value);
  12092. for(int i = 0; str[i]; i++)
  12093. {
  12094. str[i] = tolower(str[i]);
  12095. }
  12096. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12098. isSuccess = ConfigurationStatus_Accepted;
  12099. }
  12100. else
  12101. {
  12102. isSuccess = ConfigurationStatus_Rejected;
  12103. }
  12104. }
  12105. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12106. {
  12107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12108. {
  12109. strcpy(str, (const char*)value);
  12110. for(int i = 0; str[i]; i++)
  12111. {
  12112. str[i] = tolower(str[i]);
  12113. }
  12114. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12116. isSuccess = ConfigurationStatus_Accepted;
  12117. }
  12118. else
  12119. {
  12120. isSuccess = ConfigurationStatus_Rejected;
  12121. }
  12122. }
  12123. if(strcmp(key, "StopTxnAlignedData") == 0)
  12124. {
  12125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12126. {
  12127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12128. isSuccess = ConfigurationStatus_Accepted;
  12129. }
  12130. else
  12131. {
  12132. isSuccess = ConfigurationStatus_Rejected;
  12133. }
  12134. }
  12135. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12136. {
  12137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12138. {
  12139. check_ascii = value[0];
  12140. if( (check_ascii < 48) || (check_ascii > 57) )
  12141. {
  12142. isSuccess = ConfigurationStatus_Rejected;
  12143. }
  12144. else
  12145. {
  12146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12147. isSuccess = ConfigurationStatus_Accepted;
  12148. }
  12149. }
  12150. else
  12151. {
  12152. isSuccess = ConfigurationStatus_Rejected;
  12153. }
  12154. }
  12155. if(strcmp(key, "StopTxnSampledData") == 0)
  12156. {
  12157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12158. {
  12159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12160. isSuccess = ConfigurationStatus_Accepted;
  12161. }
  12162. else
  12163. {
  12164. isSuccess = ConfigurationStatus_Rejected;
  12165. }
  12166. }
  12167. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12168. {
  12169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12170. {
  12171. check_ascii = value[0];
  12172. if( (check_ascii < 48) || (check_ascii > 57) )
  12173. {
  12174. isSuccess = ConfigurationStatus_Rejected;
  12175. }
  12176. else
  12177. {
  12178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12179. isSuccess = ConfigurationStatus_Accepted;
  12180. }
  12181. }
  12182. else
  12183. {
  12184. isSuccess = ConfigurationStatus_Rejected;
  12185. }
  12186. }
  12187. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12188. {
  12189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12190. {
  12191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12192. isSuccess = ConfigurationStatus_Accepted;
  12193. }
  12194. else
  12195. {
  12196. isSuccess = ConfigurationStatus_Rejected;
  12197. }
  12198. }
  12199. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12200. {
  12201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12202. {
  12203. check_ascii = value[0];
  12204. if( (check_ascii < 48) || (check_ascii > 57) )
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. else
  12209. {
  12210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12211. isSuccess = ConfigurationStatus_Accepted;
  12212. }
  12213. }
  12214. else
  12215. {
  12216. isSuccess = ConfigurationStatus_Rejected;
  12217. }
  12218. }
  12219. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12220. {
  12221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12222. {
  12223. check_ascii = value[0];
  12224. if( (check_ascii < 48) || (check_ascii > 57) )
  12225. {
  12226. isSuccess = ConfigurationStatus_Rejected;
  12227. }
  12228. else
  12229. {
  12230. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12232. TransactionMessageAttemptsValue = atoi(value);
  12233. isSuccess = ConfigurationStatus_Accepted;
  12234. }
  12235. }
  12236. else
  12237. {
  12238. isSuccess = ConfigurationStatus_Rejected;
  12239. }
  12240. }
  12241. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12242. {
  12243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12244. {
  12245. check_ascii = value[0];
  12246. if( (check_ascii < 48) || (check_ascii > 57) )
  12247. {
  12248. isSuccess = ConfigurationStatus_Rejected;
  12249. }
  12250. else
  12251. {
  12252. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12254. TransactionMessageRetryIntervalValue = atoi(value);
  12255. isSuccess = ConfigurationStatus_Accepted;
  12256. }
  12257. }
  12258. else
  12259. {
  12260. isSuccess = ConfigurationStatus_Rejected;
  12261. }
  12262. }
  12263. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12264. {
  12265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12266. {
  12267. strcpy(str, (const char*)value);
  12268. for(int i = 0; str[i]; i++)
  12269. {
  12270. str[i] = tolower(str[i]);
  12271. }
  12272. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12274. isSuccess = ConfigurationStatus_Accepted;
  12275. }
  12276. else
  12277. {
  12278. isSuccess = ConfigurationStatus_Rejected;
  12279. }
  12280. }
  12281. if(strcmp(key, "WebSocketPingInterval") == 0)
  12282. {
  12283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12284. {
  12285. check_ascii = value[0];
  12286. if( (check_ascii < 48) || (check_ascii > 57) )
  12287. {
  12288. isSuccess = ConfigurationStatus_Rejected;
  12289. }
  12290. else
  12291. {
  12292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12293. isSuccess = ConfigurationStatus_Accepted;
  12294. }
  12295. }
  12296. else
  12297. {
  12298. isSuccess = ConfigurationStatus_Rejected;
  12299. }
  12300. }
  12301. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12302. {
  12303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12304. {
  12305. strcpy(str, (const char*)value);
  12306. for(int i = 0; str[i]; i++)
  12307. {
  12308. str[i] = tolower(str[i]);
  12309. }
  12310. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12312. isSuccess = ConfigurationStatus_Accepted;
  12313. }
  12314. else
  12315. {
  12316. isSuccess = ConfigurationStatus_Rejected;
  12317. }
  12318. }
  12319. #if 0
  12320. //For OCPP Test Case
  12321. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12322. {
  12323. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12324. {
  12325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12326. isSuccess = ConfigurationStatus_Accepted;
  12327. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12328. }
  12329. else
  12330. {
  12331. isSuccess = ConfigurationStatus_Rejected;
  12332. }
  12333. }
  12334. #endif
  12335. #if 1
  12336. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12337. {
  12338. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12339. {
  12340. strcpy(str, (const char*)value);
  12341. for(int i = 0; str[i]; i++)
  12342. {
  12343. str[i] = tolower(str[i]);
  12344. }
  12345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12346. isSuccess = ConfigurationStatus_Accepted;
  12347. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12348. }
  12349. else
  12350. {
  12351. isSuccess = ConfigurationStatus_Rejected;
  12352. }
  12353. }
  12354. #endif
  12355. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12356. {
  12357. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12358. {
  12359. check_ascii = value[0];
  12360. if( (check_ascii < 48) || (check_ascii > 57) )
  12361. {
  12362. isSuccess = ConfigurationStatus_Rejected;
  12363. }
  12364. else
  12365. {
  12366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12367. isSuccess = ConfigurationStatus_Accepted;
  12368. }
  12369. }
  12370. else
  12371. {
  12372. isSuccess = ConfigurationStatus_Rejected;
  12373. }
  12374. }
  12375. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12376. {
  12377. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12378. {
  12379. check_ascii = value[0];
  12380. if( (check_ascii < 48) || (check_ascii > 57) )
  12381. {
  12382. isSuccess = ConfigurationStatus_Rejected;
  12383. }
  12384. else
  12385. {
  12386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12387. isSuccess = ConfigurationStatus_Accepted;
  12388. }
  12389. }
  12390. else
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. }
  12395. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12396. {
  12397. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12398. {
  12399. strcpy(str, (const char*)value);
  12400. for(int i = 0; str[i]; i++)
  12401. {
  12402. str[i] = tolower(str[i]);
  12403. }
  12404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12405. isSuccess = ConfigurationStatus_Accepted;
  12406. }
  12407. else
  12408. {
  12409. isSuccess = ConfigurationStatus_Rejected;
  12410. }
  12411. }
  12412. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12413. {
  12414. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12415. {
  12416. check_ascii = value[0];
  12417. if( (check_ascii < 48) || (check_ascii > 57) )
  12418. {
  12419. isSuccess = ConfigurationStatus_Rejected;
  12420. }
  12421. else
  12422. {
  12423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12424. isSuccess = ConfigurationStatus_Accepted;
  12425. }
  12426. }
  12427. else
  12428. {
  12429. isSuccess = ConfigurationStatus_Rejected;
  12430. }
  12431. }
  12432. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12433. {
  12434. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12435. {
  12436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12437. isSuccess = ConfigurationStatus_Accepted;
  12438. }
  12439. else
  12440. {
  12441. isSuccess = ConfigurationStatus_Rejected;
  12442. }
  12443. }
  12444. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12445. {
  12446. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12447. {
  12448. check_ascii = value[0];
  12449. if( (check_ascii < 48) || (check_ascii > 57) )
  12450. {
  12451. isSuccess = ConfigurationStatus_Rejected;
  12452. }
  12453. else
  12454. {
  12455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12456. isSuccess = ConfigurationStatus_Accepted;
  12457. }
  12458. }
  12459. else
  12460. {
  12461. isSuccess = ConfigurationStatus_Rejected;
  12462. }
  12463. }
  12464. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12465. {
  12466. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12467. {
  12468. strcpy(str, (const char*)value);
  12469. for(int i = 0; str[i]; i++)
  12470. {
  12471. str[i] = tolower(str[i]);
  12472. }
  12473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12474. isSuccess = ConfigurationStatus_Accepted;
  12475. }
  12476. else
  12477. {
  12478. isSuccess = ConfigurationStatus_Rejected;
  12479. }
  12480. }
  12481. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12482. {
  12483. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12484. {
  12485. check_ascii = value[0];
  12486. if( (check_ascii < 48) || (check_ascii > 57) )
  12487. {
  12488. isSuccess = ConfigurationStatus_Rejected;
  12489. }
  12490. else
  12491. {
  12492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12493. isSuccess = ConfigurationStatus_Accepted;
  12494. }
  12495. }
  12496. else
  12497. {
  12498. isSuccess = ConfigurationStatus_Rejected;
  12499. }
  12500. }
  12501. return isSuccess;
  12502. }
  12503. int TransactionMessageAttemptsGet(void)
  12504. {
  12505. return TransactionMessageAttemptsValue;
  12506. }
  12507. int FirstHeartBeatResponse(void)
  12508. {
  12509. return FirstHeartBeat;
  12510. }
  12511. int TransactionMessageRetryIntervalGet(void)
  12512. {
  12513. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12514. }
  12515. int ReadHttpStatus(int sock)
  12516. {
  12517. //char c;
  12518. char buff[1024]="",*ptr=buff+1;
  12519. int bytes_received, status;
  12520. DEBUG_INFO("Begin Response ..\n");
  12521. while((bytes_received = recv(sock, ptr, 1, 0))){
  12522. if(bytes_received==-1){
  12523. perror("ReadHttpStatus");
  12524. exit(1);
  12525. }
  12526. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12527. ptr++;
  12528. }
  12529. *ptr=0;
  12530. ptr=buff+1;
  12531. sscanf(ptr,"%*s %d ", &status);
  12532. DEBUG_INFO("%s\n",ptr);
  12533. DEBUG_INFO("status=%d\n",status);
  12534. DEBUG_INFO("End Response ..\n");
  12535. return (bytes_received>0)?status:0;
  12536. }
  12537. //the only filed that it parsed is 'Content-Length'
  12538. int ParseHeader(int sock)
  12539. {
  12540. //char c;
  12541. char buff[1024]="",*ptr=buff+4;
  12542. int bytes_received;
  12543. DEBUG_INFO("Begin HEADER ..\n");
  12544. while((bytes_received = recv(sock, ptr, 1, 0))){
  12545. if(bytes_received==-1){
  12546. perror("Parse Header");
  12547. exit(1);
  12548. }
  12549. if(
  12550. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12551. (ptr[-1]=='\r') && (*ptr=='\n' )
  12552. ) break;
  12553. ptr++;
  12554. }
  12555. *ptr=0;
  12556. ptr=buff+4;
  12557. //printf("%s",ptr);
  12558. if(bytes_received){
  12559. ptr=strstr(ptr,"Content-Length:");
  12560. if(ptr){
  12561. sscanf(ptr,"%*s %d",&bytes_received);
  12562. }else
  12563. bytes_received=-1; //unknown size
  12564. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12565. }
  12566. DEBUG_INFO("End HEADER ..\n");
  12567. return bytes_received ;
  12568. }
  12569. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12570. {
  12571. char rmFileCmd[100]={0};
  12572. char FilePath[100]={0};
  12573. char ftpbuf[200];
  12574. int systemresult;
  12575. //DEBUG_INFO("filename=%s\n",filename);
  12576. //DEBUG_INFO("url=%s\n",url);
  12577. sprintf(FilePath,"/mnt/%s",filename);
  12578. if((access(FilePath,F_OK))!=-1)
  12579. {
  12580. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12581. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12582. system(rmFileCmd);
  12583. }
  12584. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12585. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12586. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12587. systemresult = system(ftpbuf);
  12588. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12589. if(systemresult != 0)
  12590. {
  12591. DEBUG_INFO("http DownLoad error!\n");
  12592. return FALSE;
  12593. }
  12594. return TRUE;
  12595. }
  12596. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12597. {
  12598. char rmFileCmd[100]={0};
  12599. char FilePath[100]={0};
  12600. char ftpbuf[200];
  12601. int systemresult;
  12602. //char temp[100];
  12603. sprintf(FilePath,"/mnt/%s",filename);
  12604. if((access(FilePath,F_OK))!=-1)
  12605. {
  12606. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12607. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12608. system(rmFileCmd);
  12609. }
  12610. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12611. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12612. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12613. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12614. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12615. systemresult = system(ftpbuf);
  12616. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12617. if(systemresult != 0)
  12618. {
  12619. printf("wget error!\n");
  12620. return FALSE;
  12621. }
  12622. return TRUE;
  12623. }
  12624. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12625. {
  12626. char rmFileCmd[100]={0};
  12627. char FilePath[100]={0};
  12628. char ftpbuf[200];
  12629. int systemresult;
  12630. //DEBUG_INFO("filename=%s\n",filename);
  12631. //DEBUG_INFO("url=%s\n",url);
  12632. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12633. if((access(FilePath,F_OK))!=-1)
  12634. {
  12635. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12636. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12637. system(rmFileCmd);
  12638. }
  12639. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12640. if(fp == NULL)
  12641. {
  12642. DEBUG_INFO("log is NULL\n");
  12643. return FALSE;
  12644. }
  12645. else
  12646. {
  12647. fprintf(fp, "%s\n", url);
  12648. fprintf(fp, "%s\n", filename);
  12649. fclose(fp);
  12650. }
  12651. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12652. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12653. systemresult = system(ftpbuf);
  12654. DEBUG_INFO("systemresult = %d\n",systemresult);
  12655. if(systemresult != 0)
  12656. {
  12657. DEBUG_INFO("http upload error!\n");
  12658. return FALSE;
  12659. }
  12660. return TRUE;
  12661. }
  12662. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12663. {
  12664. struct hostent* server;
  12665. char *IPbuffer;
  12666. char ftpbuf[200];
  12667. int systemresult;
  12668. // To retrieve host information
  12669. server = gethostbyname(location);
  12670. // To convert an Internet network
  12671. // address into ASCII string
  12672. IPbuffer = inet_ntoa(*((struct in_addr*)
  12673. server->h_addr_list[0]));
  12674. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12675. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12676. /* format : ftpput -u username -p passwd IP target source*/
  12677. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12678. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12679. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12680. systemresult = system(ftpbuf);
  12681. DEBUG_INFO("systemresult=%d\n",systemresult);
  12682. if(systemresult != 0)
  12683. {
  12684. DEBUG_INFO("ftpput error!\n");
  12685. return FALSE;
  12686. }
  12687. return TRUE;
  12688. }
  12689. /**
  12690. * Place the contents of the specified file into a memory buffer
  12691. *
  12692. * @param[in] filename The path and name of the file to read
  12693. * @param[out] filebuffer A pointer to the contents in memory
  12694. * @return status 0 success, 1 on failure
  12695. */
  12696. int get_file_contents(const char* filename, char** outbuffer) {
  12697. FILE* file = NULL;
  12698. long filesize;
  12699. const int blocksize = 1;
  12700. size_t readsize;
  12701. char* filebuffer;
  12702. // Open the file
  12703. file = fopen(filename, "r");
  12704. if (NULL == file)
  12705. {
  12706. printf("'%s' not opened\n", filename);
  12707. exit(EXIT_FAILURE);
  12708. }
  12709. // Determine the file size
  12710. fseek(file, 0, SEEK_END);
  12711. filesize = ftell(file);
  12712. rewind (file);
  12713. // Allocate memory for the file contents
  12714. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12715. *outbuffer = filebuffer;
  12716. if (filebuffer == NULL)
  12717. {
  12718. fputs ("malloc out-of-memory", stderr);
  12719. exit(EXIT_FAILURE);
  12720. }
  12721. // Read in the file
  12722. readsize = fread(filebuffer, blocksize, filesize, file);
  12723. if (readsize != filesize)
  12724. {
  12725. fputs ("didn't read file completely",stderr);
  12726. exit(EXIT_FAILURE);
  12727. }
  12728. // Clean exit
  12729. fclose(file);
  12730. return EXIT_SUCCESS;
  12731. }
  12732. static int selectSqlCount = 0;
  12733. static int callback(void *data, int argc, char **argv, char **azColName){
  12734. int i;
  12735. //printf("%s: ", (const char*)data);
  12736. selectSqlCount = argc;
  12737. for(i = 0; i<argc; i++){
  12738. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12739. }
  12740. //printf("\n");
  12741. return 0;
  12742. }
  12743. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12744. //int i;
  12745. //printf("%s:\n", (const char*)data);
  12746. localversion = argv[5] ? atoi(argv[5]) : 0;
  12747. //printf("localversion=%d\n", localversion);
  12748. return 0;
  12749. }
  12750. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12751. //int i;
  12752. //printf("%s:\n", (const char*)data);
  12753. //idTag
  12754. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12755. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12756. //parentIdTag
  12757. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12758. //expir_date
  12759. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12760. //status
  12761. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12762. //version
  12763. idTagQuery.listVersionInt = atoi(argv[5]);
  12764. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12765. return 0;
  12766. }
  12767. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12768. {
  12769. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12770. // printf("localversion=%d\n", localversion);
  12771. return 0;
  12772. }
  12773. //=========================================
  12774. // Sqlite3 related function
  12775. //=========================================
  12776. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12777. {
  12778. for (int i = 0; i < n_columns; i++)
  12779. {
  12780. DEBUG_INFO("%s/t", col_values[i]);
  12781. }
  12782. DEBUG_INFO("/n");
  12783. return 0;
  12784. }
  12785. void OCPP_getListVerion()
  12786. {
  12787. int rc = 0;
  12788. // const char* data = "Callback function called";
  12789. char sql[100];
  12790. char zErrMsg[100];
  12791. memset(sql, 0, 100);
  12792. memset(zErrMsg, 0, 100);
  12793. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12794. /* Execute SQL statement */
  12795. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12796. if( rc != SQLITE_OK )
  12797. {
  12798. DEBUG_INFO("SQL error: %s", zErrMsg);
  12799. }
  12800. }
  12801. void OCPP_getIdTag(char idTag[])
  12802. {
  12803. int rc = 0;
  12804. // const char* data = "Callback function called";
  12805. char sql[100];
  12806. char zErrMsg[100];
  12807. memset(sql, 0, 100);
  12808. memset(zErrMsg, 0, 100);
  12809. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12810. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12811. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12812. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12813. /* Execute SQL statement */
  12814. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12815. if( rc != SQLITE_OK )
  12816. {
  12817. DEBUG_INFO("SQL error: %s", zErrMsg);
  12818. }
  12819. //return ver;
  12820. }
  12821. void OCPP_get_TableAuthlocalAllData(void)
  12822. {
  12823. int rc = 0;
  12824. char sql[100];
  12825. char zErrMsg[100];
  12826. memset(sql, 0, 100);
  12827. memset(zErrMsg, 0, 100);
  12828. sprintf(sql,"select * from ocpp_auth_local ");
  12829. /* Execute SQL statement */
  12830. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12831. if( rc != SQLITE_OK )
  12832. {
  12833. DEBUG_INFO("SQL error: %s", zErrMsg);
  12834. }
  12835. //return ver;
  12836. }
  12837. int OCPP_cleanLocalList()
  12838. {
  12839. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12840. char *errMsg = 0;
  12841. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12842. if (SQLITE_OK != rc)
  12843. {
  12844. DEBUG_INFO("%s\n",errMsg);
  12845. return FALSE;
  12846. }
  12847. return TRUE;
  12848. }
  12849. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12850. {
  12851. int isSuccess = FALSE;
  12852. int ret = 0;
  12853. //const char* data = "Callback function called";
  12854. char sql[300];
  12855. char zErrMsg[200];
  12856. memset(sql, 0, 300);
  12857. memset(zErrMsg, 0, 200);
  12858. 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);
  12859. //* Execute SQL statement */
  12860. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12861. if( ret != SQLITE_OK )
  12862. {
  12863. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12864. return isSuccess;
  12865. }
  12866. memset(sql, 0, 300);
  12867. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12868. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12869. if( ret != SQLITE_OK )
  12870. {
  12871. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12872. return isSuccess;
  12873. }
  12874. isSuccess = TRUE;
  12875. return isSuccess;
  12876. }
  12877. void OCPP_deleteIdTag(char idTag[])
  12878. {
  12879. //int ver = 0;
  12880. //int isSuccess = FALSE;
  12881. int rc = 0;
  12882. char sql[100];
  12883. char zErrMsg[100];
  12884. memset(sql, 0, 100);
  12885. memset(zErrMsg, 0, 100);
  12886. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12887. //* Execute SQL statement */
  12888. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12889. if( rc != SQLITE_OK )
  12890. {
  12891. DEBUG_INFO("SQL error: %s", zErrMsg);
  12892. }
  12893. }
  12894. int GetOcppServerURL()
  12895. {
  12896. int result = FALSE;
  12897. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12898. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12899. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12900. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12901. {
  12902. #if 1
  12903. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12904. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12905. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12906. #endif
  12907. result = TRUE;
  12908. goto End;
  12909. }
  12910. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12911. {
  12912. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12913. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12914. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12915. result = TRUE;
  12916. goto End;
  12917. }
  12918. else
  12919. {
  12920. strcpy(OcppHost,"");
  12921. }
  12922. End:
  12923. return result;
  12924. }
  12925. int GetOcppPath()
  12926. {
  12927. int result = FALSE;
  12928. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12929. {
  12930. if(OcppTempPath == NULL)
  12931. {
  12932. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12933. }
  12934. else
  12935. {
  12936. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12937. }
  12938. result = TRUE;
  12939. goto End;
  12940. }
  12941. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12942. {
  12943. if(OcppTempPath == NULL)
  12944. {
  12945. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12946. }
  12947. else
  12948. {
  12949. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12950. }
  12951. result = TRUE;
  12952. goto End;
  12953. }
  12954. else
  12955. {
  12956. strcpy(OcppPath,"");
  12957. }
  12958. End:
  12959. return result;
  12960. }
  12961. int GetOcppPort()
  12962. {
  12963. return OcppPort;
  12964. }
  12965. int GetOcppConnStatus(void)
  12966. {
  12967. return ShmOCPP16Data->OcppConnStatus;
  12968. }
  12969. void SetOcppConnStatus(uint8_t status)
  12970. {
  12971. ShmOCPP16Data->OcppConnStatus = status;
  12972. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12973. }
  12974. int GetHeartBeatWithNOResponse(void)
  12975. {
  12976. return HeartBeatWithNOResponse;
  12977. }
  12978. void SetHeartBeatWithNOResponse(void)
  12979. {
  12980. HeartBeatWithNOResponse = 0;
  12981. }
  12982. void GetStartTransactionIdTag(int gun_index)
  12983. {
  12984. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  12985. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12986. }
  12987. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  12988. {
  12989. char ch;
  12990. FILE *fptr1;
  12991. int temptransactionId;
  12992. char str[100]={0};
  12993. temptransactionId = 0;
  12994. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12995. {
  12996. DEBUG_INFO("IdTag is empty.\n");
  12997. return temptransactionId;
  12998. }
  12999. /*------ Read the file ----------------*/
  13000. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13001. if (!fptr1)
  13002. {
  13003. DEBUG_INFO("QueueTransactionId file open error.\n");
  13004. //printf(" File not found or unable to open the input file!!\n");
  13005. return temptransactionId;
  13006. }
  13007. ch=fgetc(fptr1);
  13008. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13009. rewind(fptr1);
  13010. if(ch!=EOF)
  13011. {
  13012. // printf("%c",ch);
  13013. while (fgets(str, 100, fptr1) != NULL)
  13014. {
  13015. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13016. if(str[0]=='\0')
  13017. {
  13018. break;
  13019. }
  13020. char *revbuf[8] = {0}; //存放分割後的子字串
  13021. int num = 0;//分割後子字串的個數
  13022. DEBUG_INFO("str: %s\n", str);
  13023. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13024. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13025. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13026. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13027. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13028. {
  13029. if(isStopTransaction)
  13030. {
  13031. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13032. {
  13033. temptransactionId = atoi(revbuf[2]);
  13034. break;
  13035. }
  13036. }
  13037. else
  13038. {
  13039. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13040. {
  13041. temptransactionId = atoi(revbuf[2]);
  13042. break;
  13043. }
  13044. }
  13045. }
  13046. }
  13047. }
  13048. else
  13049. DEBUG_INFO("EOF\n");
  13050. fclose(fptr1);
  13051. /*------- End of reading ---------------*/
  13052. return temptransactionId;
  13053. }
  13054. void SetTransactionIdZero(int transactionId)
  13055. {
  13056. char ch;
  13057. FILE *fptr1, *fptr2;
  13058. int temptransactionId = 0;
  13059. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13060. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13061. if (!fptr1)
  13062. {
  13063. //printf(" File not found or unable to open the input file!!\n");
  13064. return ;
  13065. }
  13066. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13067. if (!fptr2)
  13068. {
  13069. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13070. fclose(fptr1);
  13071. return ;
  13072. }
  13073. ch=fgetc(fptr1);
  13074. rewind(fptr1);
  13075. if(ch!=EOF)
  13076. {
  13077. // copy all contents to the temporary file except the specific line
  13078. while (fgets(str, 100, fptr1) != NULL)
  13079. {
  13080. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13081. if(str[0]=='\0')
  13082. {
  13083. break;
  13084. }
  13085. char *revbuf[8] = {0};
  13086. int num = 0;
  13087. strcpy(strtemp, str);
  13088. splitstring(str,",",revbuf,&num);
  13089. if(revbuf[2][0] != '\0')
  13090. {
  13091. temptransactionId = atoi(revbuf[2]);
  13092. if(transactionId != temptransactionId)
  13093. {
  13094. fprintf(fptr2, "%s\n", strtemp);
  13095. }
  13096. }
  13097. }
  13098. }
  13099. fclose(fptr1);
  13100. fclose(fptr2);
  13101. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13102. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13103. /*------ Read the file ----------------*/
  13104. }
  13105. int InternetDisconnect(void)
  13106. {
  13107. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13108. }
  13109. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13110. void storeTempStopTransaction(int gun_index)
  13111. {
  13112. char guid[37]={0};
  13113. int tempIndex = 0;
  13114. DEBUG_INFO("storeTempStopTransaction...\n");
  13115. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13116. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13118. if(gunType[gun_index] == 'J')
  13119. {
  13120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13121. {
  13122. tempIndex = ((gun_index==2) ? 1: 0);
  13123. }
  13124. else
  13125. {
  13126. tempIndex = gun_index;
  13127. }
  13128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13129. {
  13130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13131. {
  13132. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13133. }
  13134. }// END OF CHAdeMO_QUANTITY
  13135. }
  13136. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13137. {
  13138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13139. {
  13140. tempIndex = ((gun_index==2) ? 1: 0);
  13141. }
  13142. else
  13143. {
  13144. tempIndex = gun_index;
  13145. }
  13146. for (int index = 0; index < CCS_QUANTITY; index++)
  13147. {
  13148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13149. {
  13150. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13151. }
  13152. }// END OF CCS_QUANTITY
  13153. }
  13154. else if(gunType[gun_index] == 'G')
  13155. {
  13156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13157. {
  13158. tempIndex = ((gun_index==2) ? 1: 0);
  13159. }
  13160. else
  13161. {
  13162. tempIndex = gun_index;
  13163. }
  13164. for (int index = 0; index < GB_QUANTITY; index++)
  13165. {
  13166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13167. {
  13168. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13169. }
  13170. }// END OF GB_QUANTITY
  13171. }
  13172. else
  13173. {
  13174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13175. {
  13176. tempIndex = 2;
  13177. }
  13178. else
  13179. {
  13180. tempIndex = gun_index;
  13181. }
  13182. for (int index = 0; index < AC_QUANTITY; index++)
  13183. {
  13184. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13185. {
  13186. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13187. }
  13188. }// END OF AC_QUANTITY
  13189. }
  13190. //Stop Transaction Time
  13191. struct timeval tmnow;
  13192. struct tm *tm;
  13193. char buf[28];//, usec_buf[6];
  13194. gettimeofday(&tmnow, NULL);
  13195. time_t t;
  13196. t = time(NULL);
  13197. /*UTC time and date*/
  13198. tm = gmtime(&t);
  13199. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13201. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13203. random_uuid(guid);
  13204. /***********************************transactionData******************************************************/
  13205. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13207. //=================================
  13208. //1. Transaction_Begin
  13209. //=================================
  13210. //============================== Energy.Active.Import.Interval ===========================================
  13211. //idx_sample=0;
  13212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13215. 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*/]);
  13216. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13217. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13218. {
  13219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13220. }
  13221. else
  13222. {
  13223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13224. }
  13225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13227. //=================================
  13228. //2. Transaction_End
  13229. //=================================
  13230. //2.1====================================== Current.Import L1 ==============================================
  13231. //idx_sample=1;
  13232. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13233. if(gunType[gun_index] == 'J')
  13234. {
  13235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13236. {
  13237. tempIndex = ((gun_index==2) ? 1: 0);
  13238. }
  13239. else
  13240. {
  13241. tempIndex = gun_index;
  13242. }
  13243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13244. {
  13245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13246. {
  13247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13248. }
  13249. }// End of for CHAdeMO_QUANTITY
  13250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13251. }
  13252. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13253. {
  13254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13255. {
  13256. tempIndex = ((gun_index==2) ? 1: 0);
  13257. }
  13258. else
  13259. {
  13260. tempIndex = gun_index;
  13261. }
  13262. for (int index = 0; index < CCS_QUANTITY; index++)
  13263. {
  13264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13265. {
  13266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13267. }
  13268. }// End of for CCS_QUANTITY
  13269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13270. }
  13271. else if(gunType[gun_index] == 'G')
  13272. {
  13273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13274. {
  13275. tempIndex = ((gun_index==2) ? 1: 0);
  13276. }
  13277. else
  13278. {
  13279. tempIndex = gun_index;
  13280. }
  13281. for (int index = 0; index < GB_QUANTITY; index++)
  13282. {
  13283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13284. {
  13285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13286. }
  13287. }// End of for GB_QUANTITY
  13288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13289. }
  13290. else
  13291. {
  13292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13293. {
  13294. tempIndex = 2;
  13295. }
  13296. else
  13297. {
  13298. tempIndex = gun_index;
  13299. }
  13300. for (int index = 0; index < AC_QUANTITY; index++)
  13301. {
  13302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13303. {
  13304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13305. }
  13306. }// End of for AC_QUANTITY
  13307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13308. }
  13309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13312. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13315. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13316. //idx_sample=2;
  13317. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13318. if(gunType[gun_index] == 'J')
  13319. {
  13320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13321. {
  13322. tempIndex = ((gun_index==2) ? 1: 0);
  13323. }
  13324. else
  13325. {
  13326. tempIndex = gun_index;
  13327. }
  13328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13329. {
  13330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13331. {
  13332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13333. }
  13334. }// END OF CHAdeMO_QUANTITY
  13335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13336. }
  13337. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13338. {
  13339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13340. {
  13341. tempIndex = ((gun_index==2) ? 1: 0);
  13342. }
  13343. else
  13344. {
  13345. tempIndex = gun_index;
  13346. }
  13347. for (int index = 0; index < CCS_QUANTITY; index++)
  13348. {
  13349. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13350. {
  13351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13352. }
  13353. }// END OF CCS_QUANTITY
  13354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13355. }
  13356. else if(gunType[gun_index] == 'G')
  13357. {
  13358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13359. {
  13360. tempIndex = ((gun_index==2) ? 1: 0);
  13361. }
  13362. else
  13363. {
  13364. tempIndex = gun_index;
  13365. }
  13366. for (int index = 0; index < GB_QUANTITY; index++)
  13367. {
  13368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13369. {
  13370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13371. }
  13372. }// END OF GB_QUANTITY
  13373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13374. }
  13375. else
  13376. {
  13377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13378. {
  13379. tempIndex = 2;
  13380. }
  13381. else
  13382. {
  13383. tempIndex = gun_index;
  13384. }
  13385. for (int index = 0; index < AC_QUANTITY; index++)
  13386. {
  13387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13388. {
  13389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13390. }
  13391. }// END OF AC_QUANTITY
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13393. }
  13394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13397. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13400. //2.3====================================== Power.Active.Import =========================================
  13401. //idx_sample=3;
  13402. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13403. if(gunType[gun_index] == 'J')
  13404. {
  13405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13406. {
  13407. tempIndex = ((gun_index==2) ? 1: 0);
  13408. }
  13409. else
  13410. {
  13411. tempIndex = gun_index;
  13412. }
  13413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13414. {
  13415. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13416. {
  13417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13418. }
  13419. } // End for CHAdeMO_QUANTITY
  13420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13421. }
  13422. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13423. {
  13424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13425. {
  13426. tempIndex = ((gun_index==2) ? 1: 0);
  13427. }
  13428. else
  13429. {
  13430. tempIndex = gun_index;
  13431. }
  13432. for (int index = 0; index < CCS_QUANTITY; index++)
  13433. {
  13434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13435. {
  13436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13437. }
  13438. } // END for CCS_QUANTITY
  13439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13440. }
  13441. else if(gunType[gun_index] == 'G')
  13442. {
  13443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13444. {
  13445. tempIndex = ((gun_index==2) ? 1: 0);
  13446. }
  13447. else
  13448. {
  13449. tempIndex = gun_index;
  13450. }
  13451. for (int index = 0; index < GB_QUANTITY; index++)
  13452. {
  13453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13454. {
  13455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13456. }
  13457. }// END for GB_QUANTITY
  13458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13459. }
  13460. else
  13461. {
  13462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13463. {
  13464. tempIndex = 2;
  13465. }
  13466. else
  13467. {
  13468. tempIndex = gun_index;
  13469. }
  13470. for (int index = 0; index < AC_QUANTITY; index++)
  13471. {
  13472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13473. {
  13474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13475. }
  13476. } // END for AC_QUANTITY
  13477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13478. }
  13479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13482. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13485. //2.4====================================== Voltage L1 ====================================================
  13486. //idx_sample=4;
  13487. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13488. if(gunType[gun_index] == 'J')
  13489. {
  13490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13491. {
  13492. tempIndex = ((gun_index==2) ? 1: 0);
  13493. }
  13494. else
  13495. {
  13496. tempIndex = gun_index;
  13497. }
  13498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13499. {
  13500. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13501. {
  13502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13503. }
  13504. } // END OF FOR CHAdeMO_QUANTITY
  13505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13506. }
  13507. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  13518. {
  13519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13522. }
  13523. } // END OF FOR CCS_QUANTITY
  13524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13525. }
  13526. else if(gunType[gun_index] == 'G')
  13527. {
  13528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13529. {
  13530. tempIndex = ((gun_index==2) ? 1: 0);
  13531. }
  13532. else
  13533. {
  13534. tempIndex = gun_index;
  13535. }
  13536. for (int index = 0; index < GB_QUANTITY; index++)
  13537. {
  13538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13539. {
  13540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13541. }
  13542. } // END OF FOR GB_QUANTITY
  13543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13544. }
  13545. else
  13546. {
  13547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13548. {
  13549. tempIndex = 2;
  13550. }
  13551. else
  13552. {
  13553. tempIndex = gun_index;
  13554. }
  13555. for (int index = 0; index < AC_QUANTITY; index++)
  13556. {
  13557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13558. {
  13559. 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
  13560. }
  13561. } // END OF FOR AC_QUANTITY
  13562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13563. }
  13564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13567. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13570. //2.5============================================== SoC =========================================================
  13571. //idx_sample=5;
  13572. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13573. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13574. {
  13575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13576. {
  13577. tempIndex = ((gun_index==2) ? 1: 0);
  13578. }
  13579. else
  13580. {
  13581. tempIndex = gun_index;
  13582. }
  13583. if(gunType[gun_index] == 'J')
  13584. {
  13585. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13586. {
  13587. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13588. {
  13589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13590. }
  13591. }
  13592. }
  13593. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13594. {
  13595. for (int index = 0; index < CCS_QUANTITY; index++)
  13596. {
  13597. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13598. {
  13599. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13600. }
  13601. }
  13602. }
  13603. else if(gunType[gun_index] == 'G')
  13604. {
  13605. for (int index = 0; index < GB_QUANTITY; index++)
  13606. {
  13607. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13608. {
  13609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13610. }
  13611. }
  13612. }
  13613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13619. } // END FOR DC CASE
  13620. //2.6====================================== Current.Import L2 ==============================================
  13621. // idx_sample=6;
  13622. // AC 3 phase L2 current
  13623. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13624. {
  13625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13626. {
  13627. tempIndex = 2;
  13628. }
  13629. else
  13630. {
  13631. tempIndex = gun_index;
  13632. }
  13633. for (int index = 0; index < AC_QUANTITY; index++)
  13634. {
  13635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13636. {
  13637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13638. }
  13639. }// End of for AC_QUANTITY
  13640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13641. }
  13642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13647. //2.7====================================== Current.Import L3 ==============================================
  13648. // idx_sample=7;
  13649. // AC 3 phase L3 current
  13650. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13651. {
  13652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13653. {
  13654. tempIndex = 2;
  13655. }
  13656. else
  13657. {
  13658. tempIndex = gun_index;
  13659. }
  13660. for (int index = 0; index < AC_QUANTITY; index++)
  13661. {
  13662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13663. {
  13664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13665. }
  13666. }// End of for AC_QUANTITY
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13668. }
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13674. //2.9====================================== Voltage L2 ====================================================
  13675. //idx_sample=8;
  13676. // AC 3 phase L2 volatge
  13677. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13678. {
  13679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13680. {
  13681. tempIndex = 2;
  13682. }
  13683. else
  13684. {
  13685. tempIndex = gun_index;
  13686. }
  13687. for (int index = 0; index < AC_QUANTITY; index++)
  13688. {
  13689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13690. {
  13691. 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
  13692. }
  13693. } // END OF FOR AC_QUANTITY
  13694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13695. }
  13696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13701. //2.10====================================== Voltage L3 ====================================================
  13702. //idx_sample=9;
  13703. // AC 3 phase L3 volatge
  13704. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13705. {
  13706. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13707. {
  13708. tempIndex = 2;
  13709. }
  13710. else
  13711. {
  13712. tempIndex = gun_index;
  13713. }
  13714. for (int index = 0; index < AC_QUANTITY; index++)
  13715. {
  13716. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13717. {
  13718. 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
  13719. }
  13720. } // END OF FOR AC_QUANTITY
  13721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13722. }
  13723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13728. //======================================== Message create ==============================================
  13729. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13730. {
  13731. 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\"}]}]}]"
  13732. ,gun_index+1
  13733. ,MESSAGE_TYPE_CALL
  13734. ,guid
  13735. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13736. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13737. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13739. ,"PowerLoss"
  13740. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13783. );
  13784. }
  13785. else
  13786. {
  13787. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13788. {
  13789. 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\"}]}]}]"
  13790. ,gun_index+1
  13791. ,MESSAGE_TYPE_CALL
  13792. ,guid
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13797. ,"PowerLoss"
  13798. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13834. );
  13835. }
  13836. else
  13837. {
  13838. 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\"}]}]}]"
  13839. ,gun_index+1
  13840. ,MESSAGE_TYPE_CALL
  13841. ,guid
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13846. ,"PowerLoss"
  13847. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13911. );
  13912. }
  13913. }
  13914. // Check File "TempStopTransaction" Exist
  13915. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13916. {
  13917. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13918. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13919. }
  13920. else
  13921. {
  13922. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13923. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13924. if(log == NULL)
  13925. {
  13926. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13927. return ;
  13928. }
  13929. else
  13930. {
  13931. fclose(log);
  13932. }
  13933. }
  13934. //Add TempStopTransaction | Update TempStopTransaction
  13935. // open file for writing
  13936. FILE *outfile;
  13937. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13938. //DEBUG_INFO("data = %s\n", queuedata);
  13939. fputs(queuedata, outfile);
  13940. fputs("\n", outfile);
  13941. fclose (outfile);
  13942. }
  13943. void checkTempStopTransaction(int gun_index)
  13944. {
  13945. FILE *fptr1;
  13946. char ch;
  13947. char str[QUEUE_MESSAGE_LENGTH]={0};
  13948. char guid[37]={0};
  13949. char tempdata[65]={0};
  13950. char connectorStr[2]={0};
  13951. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13952. //TempStopTransaction格式: 槍號,StopTransaction封包
  13953. if (!fptr1)
  13954. {
  13955. //printf(" File not found or unable to open the input file!!\n");
  13956. return ;
  13957. }
  13958. ch=fgetc(fptr1);
  13959. //printf(" Now the content of the file %s is : \n",fname);
  13960. rewind(fptr1);
  13961. if(ch!=EOF)
  13962. {
  13963. // copy all contents to the temporary file except the specific line
  13964. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13965. {
  13966. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13967. if(str[0]=='\0')
  13968. {
  13969. break;
  13970. }
  13971. //TempStopTransaction格式: 槍號,StopTransaction封包
  13972. strncpy(connectorStr, str, 1);
  13973. if(atoi(connectorStr) != (gun_index+1))
  13974. {
  13975. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13976. return ;
  13977. }
  13978. //random_uuid(guid);
  13979. strncpy(guid, str+6, 36); //copy guid
  13980. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13981. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13982. {
  13983. DEBUG_INFO("StopTransaction mapitem pass\n");
  13984. }
  13985. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13986. memset(str,0,ARRAY_SIZE(str));
  13987. }
  13988. }
  13989. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13990. fclose(fptr1);
  13991. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13992. }
  13993. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13994. {
  13995. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13996. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13997. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13998. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13999. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14000. }
  14001. int GetWebSocketPingInterval(void)
  14002. {
  14003. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14004. }
  14005. int GetServerSign(void)
  14006. {
  14007. return server_sign;
  14008. }
  14009. void SetServerSign(int value)
  14010. {
  14011. server_sign = value;
  14012. }
  14013. int GetBootNotificationInterval(void)
  14014. {
  14015. return BootNotificationInterval;
  14016. }
  14017. int GetInternetConn(void)
  14018. {
  14019. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14020. }
  14021. void InitialSystemValue(void)
  14022. {
  14023. int connectorIndex = 0;
  14024. //int valueASCII = 0;
  14025. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14026. gunTotalNumber=0;
  14027. SystemInitial = 0;
  14028. localversion=0;
  14029. BootNotificationInterval = 0;
  14030. authorizeRetryTimes = 0;
  14031. GunStatusInterval = 10;
  14032. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14033. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14034. //Hear Beat
  14035. HeartBeatWithNOResponse = 0;
  14036. HeartBeatCountPerHour = 0;
  14037. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14038. FirstHeartBeat = 0;
  14039. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14040. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14041. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14042. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14043. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14044. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14045. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14046. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14047. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14048. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14049. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14050. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14051. memset(gunType, 0, ARRAY_SIZE(gunType));
  14052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14053. {
  14054. //check connector / socket type (index: 8, 9, 10)
  14055. for(int index=7; index <10 ; index++)
  14056. {
  14057. if(index != 8)
  14058. {
  14059. // DC Connector
  14060. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14061. {
  14062. SystemInitial = SystemInitial + 1;
  14063. gunTotalNumber = gunTotalNumber + 1;
  14064. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14065. connectorIndex = connectorIndex + 1;
  14066. }
  14067. }
  14068. else
  14069. {
  14070. // AC Connector
  14071. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14072. {
  14073. SystemInitial = SystemInitial + 1;
  14074. gunTotalNumber = gunTotalNumber + 1;
  14075. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14076. connectorIndex = connectorIndex + 1;
  14077. }
  14078. }
  14079. }
  14080. //DEBUG_INFO("DC ...\n");
  14081. }
  14082. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14083. {
  14084. //check connector / socket type (index: 8, 9, 10)
  14085. for(int index=7; index <10 ; index++)
  14086. {
  14087. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14088. {
  14089. SystemInitial = SystemInitial + 1;
  14090. gunTotalNumber = gunTotalNumber + 1;
  14091. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14092. connectorIndex = connectorIndex + 1;
  14093. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14094. }
  14095. }
  14096. }
  14097. //Status && ConnectorPlugIn Setting
  14098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14099. {
  14100. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14101. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14102. }
  14103. for (int index = 0; index < CCS_QUANTITY; index++)
  14104. {
  14105. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14106. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14107. }
  14108. for (int index = 0; index < GB_QUANTITY; index++)
  14109. {
  14110. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14111. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14112. }
  14113. for (int index = 0; index < AC_QUANTITY; index++)
  14114. {
  14115. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14116. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14117. }
  14118. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14119. {
  14120. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14121. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14122. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14123. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14124. }
  14125. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14126. clientTime.Heartbeat=time((time_t*)NULL);
  14127. sleep(1);
  14128. }
  14129. void LWS_Send(char * str)
  14130. {
  14131. //=====================================================
  14132. // Check InternetConn 0: disconnected, 1: connected
  14133. //====================================================
  14134. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14135. {
  14136. DEBUG_INFO("offline now !!!\n");
  14137. return;
  14138. }
  14139. pthread_mutex_lock(&lock_send);
  14140. memset(SendBuffer, 0, SendBufLen);
  14141. sprintf((char *)SendBuffer, "%s", str);
  14142. pthread_mutex_unlock(&lock_send);
  14143. lws_callback_on_writable(wsi_client);
  14144. //lws_service(context, 0);
  14145. //sleep(1);
  14146. }